diff --git a/htdocs/adherents/card_subscriptions.php b/htdocs/adherents/card_subscriptions.php index 491cbcf8b79..8e2eb19c19f 100644 --- a/htdocs/adherents/card_subscriptions.php +++ b/htdocs/adherents/card_subscriptions.php @@ -235,8 +235,8 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio { $db->begin(); + // Create subscription (and bank record if option is 'bankdirect') $crowid=$adh->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $option); - if ($crowid <= 0) { $error++; @@ -297,9 +297,9 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio // Validate invoice $result=$invoice->validate($user); + // Add payment if ($option == 'bankviainvoice') { - // Now we add payment require_once(DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'); require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); @@ -324,7 +324,7 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio if (! $error) { - $result=$paiement->addLinkInvoiceBank($user,'(SubscriptionPayment)',$accountid,$emetteur_nom,$emetteur_banque); + $result=$paiement->addPaymentToBank($user,'payment','(SubscriptionPayment)',$accountid,$emetteur_nom,$emetteur_banque); if (! $result > 0) { $errmsg=$paiement->error; diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 0fa93b6fe1e..2633b578ad1 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -1229,12 +1229,6 @@ class Adherent extends CommonObject } } - // Create invoice and payment - if ($option == 'bankviainvoice' && $accountid) - { - // TODO - } - // Change properties of object (used by triggers) $this->last_subscription_date=$dateop; $this->last_subscription_amount=$montant; diff --git a/htdocs/cashdesk/validation_verif.php b/htdocs/cashdesk/validation_verif.php index 80d623b11f9..03b294ca34b 100644 --- a/htdocs/cashdesk/validation_verif.php +++ b/htdocs/cashdesk/validation_verif.php @@ -244,69 +244,29 @@ switch ( $_GET['action'] ) $paiement_id = $payment->create($user); if ($paiement_id > 0) { - // Ajout d'une ecriture sur le compte bancaire - if ($conf->banque->enabled) - { - $bankaccountid=0; - if ( $obj_facturation->mode_reglement() == 'ESP' ) - { - $bankaccountid=$conf_fkaccount_cash; - } - if ( $obj_facturation->mode_reglement() == 'CHQ' ) - { - $bankaccountid=$conf_fkaccount_cheque; - } - if ( $obj_facturation->mode_reglement() == 'CB' ) - { - $bankaccountid=$conf_fkaccount_cb; - } + $bankaccountid=0; + if ( $obj_facturation->mode_reglement() == 'ESP' ) + { + $bankaccountid=$conf_fkaccount_cash; + } + if ( $obj_facturation->mode_reglement() == 'CHQ' ) + { + $bankaccountid=$conf_fkaccount_cheque; + } + if ( $obj_facturation->mode_reglement() == 'CB' ) + { + $bankaccountid=$conf_fkaccount_cb; + } - if ($bankaccountid > 0) - { - // Insertion dans llx_bank - $label = "(CustomerInvoicePayment)"; - $acc = new Account($db, $bankaccountid); - - $bank_line_id = $acc->addline($payment->datepaye, - $payment->paiementid, // Payment mode id or code ("CHQ or VIR for example") - $label, - $obj_facturation->prix_total_ttc(), - $payment->num_paiement, - '', - $user, - '', - ''); - - // Mise a jour fk_bank dans llx_paiement. - // On connait ainsi le paiement qui a genere l'ecriture bancaire - if ($bank_line_id > 0) - { - $payment->update_fk_bank($bank_line_id); - // Mise a jour liens (pour chaque facture concernees par le paiement) - foreach ($payment->amounts as $key => $value) - { - $facid = $key; - $fac = new Facture($db); - $fac->fetch($facid); - $fac->fetch_client(); - $acc->add_url_line($bank_line_id, - $paiement_id, - DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', - '(paiement)', - 'payment'); - $acc->add_url_line($bank_line_id, - $fac->client->id, - DOL_URL_ROOT.'/compta/fiche.php?socid=', - $fac->client->nom, - 'company'); - } - } - else - { - $error++; - } - } - } + if (! $error) + { + $result=$payment->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$bankaccountid,'',''); + if (! $result > 0) + { + $errmsg=$paiement->error; + $error++; + } + } } else { diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 744836cf88a..2cee3af5905 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -202,6 +202,7 @@ class Account extends CommonObject // Clean parameters $emetteur=trim($emetteur); $banque=trim($banque); + if (is_numeric($oper)) // Clean oper to have a code instead of a rowid { $sql ="SELECT code FROM ".MAIN_DB_PREFIX."c_paiement"; @@ -236,7 +237,6 @@ class Account extends CommonObject return -3; } - $this->db->begin(); $datev = $date; diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index e7404dcce9a..022028257f2 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -48,6 +48,7 @@ $amountsresttopay=array(); $addwarning=0; // Security check +$socid=0; if ($user->societe_id > 0) { $socid = $user->societe_id; @@ -166,7 +167,7 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes') if (! $error) { - $result=$paiement->addLinkInvoiceBank($user,'(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']); + $result=$paiement->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']); if (! $result > 0) { $errmsg=$paiement->error; diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 320174213d9..fe2271a492d 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -304,13 +304,14 @@ class Paiement * A record into bank for payment with links between this bank record and invoices of payment. * All payment properties must have been set first like after a call to create(). * @param user Object of user making payment + * @param mode 'payment', 'payment_supplier' * @param label Label to use in bank record * @param accountid Id of bank account to do link with * @param emetteur_nom Name of transmitter * @param emetteur_banque Name of bank * @return int <0 if KO, >0 if OK */ - function addLinkInvoiceBank($user,$label,$accountid,$emetteur_nom,$emetteur_banque) + function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque) { global $conf; @@ -323,11 +324,15 @@ class Paiement $acc = new Account($this->db); $acc->fetch($accountid); + $total=$this->total; + if ($mode == 'payment_supplier') $total=-$total; + if ($mode == 'payment_sc') $total=-$total; + // Insert payment into llx_bank $bank_line_id = $acc->addline($this->datepaye, $this->paiementid, // Payment mode id or code ("CHQ or VIR for example") $label, - $this->total, + $total, $this->num_paiement, '', $user, @@ -344,33 +349,50 @@ class Paiement $error++; dol_print_error($this->db); } - // Add link 'payment' in bank_url between payment and bank transaction - $result=$acc->add_url_line($bank_line_id, - $this->id, - DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', - '(paiement)', - 'payment'); - if ($result <= 0) + + // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction + $url=''; + if ($mode == 'payment') $url=DOL_URL_ROOT.'/compta/paiement/fiche.php?id='; + if ($mode == 'payment_supplier') $url=DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='; + if ($url) { - $error++; - dol_print_error($this->db); + $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } } + // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment) $linkaddedforthirdparty=array(); foreach ($this->amounts as $key => $value) { - $fac = new Facture($this->db); - $fac->fetch($key); - $fac->fetch_thirdparty(); // This should be always same third party but we loop in case of. - if (! in_array($fac->client->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty + if ($mode == 'payment') { - $result=$acc->add_url_line($bank_line_id, - $fac->client->id, - DOL_URL_ROOT.'/compta/fiche.php?socid=', - $fac->client->nom, - 'company'); - if ($result <= 0) dol_print_error($this->db); - $linkaddedforthirdparty[$fac->client->id]=$fac->client->id; // Mark as done for this thirdparty + $fac = new Facture($this->db); + $fac->fetch($key); + $fac->fetch_thirdparty(); // This should be always same third party but we loop in case of. + if (! in_array($fac->client->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty + { + $result=$acc->add_url_line($bank_line_id, $fac->client->id, + DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom, 'company'); + if ($result <= 0) dol_print_error($this->db); + $linkaddedforthirdparty[$fac->client->id]=$fac->client->id; // Mark as done for this thirdparty + } + } + if ($mode == 'payment_supplier') + { + $fac = new FactureFournisseur($this->db); + $fac->fetch($key); + $fac->fetch_fournisseur(); // This should be always same third party but we loop in case of. + if (! in_array($fac->client->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty + { + $result=$acc->add_url_line($bank_line_id, $fac->fournisseur->id, + DOL_URL_ROOT.'/fourn/fiche.php?socid=', $fac->fournisseur->nom, 'company'); + if ($result <= 0) dol_print_error($this->db); + $linkaddedforthirdparty[$fac->fournisseur->id]=$fac->fournisseur->id; // Mark as done for this thirdparty + } } } } diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index 0e028582fe6..6a7b4b161fb 100755 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -30,11 +30,12 @@ include_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); $langs->load("bills"); $chid=isset($_GET["id"])?$_GET["id"]:$_POST["id"]; +$amounts = array(); -// Securite acces client +// Security check +$socid=0; if ($user->societe_id > 0) { - $action = ''; $socid = $user->societe_id; } @@ -74,14 +75,12 @@ if ($_POST["action"] == 'add_paiement') $paymentid = 0; // Read possible payments - $amounts = array(); foreach ($_POST as $key => $value) { if (substr($key,0,7) == 'amount_') { $other_chid = substr($key,7); - - $amounts[$other_chid] = $_POST[$key]; + $amounts[$other_chid] = price2num($_POST[$key]); } } @@ -95,57 +94,38 @@ if ($_POST["action"] == 'add_paiement') $paiement->paiementtype = $_POST["paiementtype"]; $paiement->num_paiement = $_POST["num_paiement"]; $paiement->note = $_POST["note"]; - $paymentid = $paiement->create($user); - $socialcontrib = new ChargeSociales($db); - $socialcontrib->fetch($paiement->chid); - - if ($paymentid > 0) + if (! $error) { - // On determine le montant total du paiement - $total=0; - foreach ($paiement->amounts as $key => $value) - { - $chid = $key; - $value = trim($value); - $amount = price2num(trim($value), 'MT'); // Un round est ok si nb avec '.' - $total += $amount; - } - - // Insertion dans llx_bank - $langs->load("banks"); - $label = $langs->transnoentities("SocialContributionPayment"); - $acc = new Account($db, $_POST["accountid"]); - $bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -$total, $paiement->num_paiement, '', $user); - - // Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a genere l'ecriture bancaire - if ($bank_line_id > 0) - { - $paiement->update_fk_bank($bank_line_id); - - // Mise a jour liens (pour chaque charge concernee par le paiement) - foreach ($paiement->amounts as $key => $value) - { - $acc->add_url_line($bank_line_id, $chid, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc'); - $acc->add_url_line($bank_line_id, $paymentid, DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id=', '(paiement)','payment_sc'); - } - - $db->commit(); - - $loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid; - Header("Location: ".$loc); - exit; - } - else { - $db->rollback(); - $mesg = "Echec de la creation entree compte: ".$db->error(); - } - } - else - { - $db->rollback(); - $mesg = "Failed to create payment: paiement_id=".$paymentid." ".$db->error(); + $paymentid = $paiement->create($user); + if (! $paymentid > 0) + { + $errmsg=$paiement->error; + $error++; + } } + + if (! $error) + { + $result=$paiement->addPaymentToBank($user,'payment_sc','(SocialContributionPayment)',$_POST['accountid'],'',''); + if (! $result > 0) + { + $errmsg=$paiement->error; + $error++; + } + } + + if (! $error) + { + $db->commit(); + $loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid; + Header('Location: '.$loc); + exit; + } + else + { + $db->rollback(); + } } $_GET["action"]='create'; diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index 33101332829..942fe3582fb 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -374,7 +374,7 @@ class PaiementCharge extends CommonObject * \brief Constructor * \param DB Database handler */ - function Paiementcharge($DB) + function PaiementCharge($DB) { $this->db = $DB; return 1; @@ -414,7 +414,6 @@ class PaiementCharge extends CommonObject $total=0; foreach ($this->amounts as $key => $value) { - $facid = $key; $amount = price2num(trim($value), 'MT'); $total += $amount; } @@ -758,6 +757,100 @@ class PaiementCharge extends CommonObject } + /** + * A record into bank for payment with links between this bank record and invoices of payment. + * All payment properties must have been set first like after a call to create(). + * @param user Object of user making payment + * @param mode 'payment_sc' + * @param label Label to use in bank record + * @param accountid Id of bank account to do link with + * @param emetteur_nom Name of transmitter + * @param emetteur_banque Name of bank + * @return int <0 if KO, >0 if OK + */ + function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque) + { + global $conf; + + $error=0; + + if ($conf->banque->enabled) + { + require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); + + $acc = new Account($this->db); + $acc->fetch($accountid); + + $total=$this->total; + if ($mode == 'payment_sc') $total=-$total; + + // Insert payment into llx_bank + $bank_line_id = $acc->addline($this->datepaye, + $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example") + $label, + $total, + $this->num_paiement, + '', + $user, + $emetteur_nom, + $emetteur_banque); + + // Mise a jour fk_bank dans llx_paiement. + // On connait ainsi le paiement qui a genere l'ecriture bancaire + if ($bank_line_id > 0) + { + $result=$this->update_fk_bank($bank_line_id); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + + // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction + $url=''; + if ($mode == 'payment_sc') $url=DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='; + if ($url) + { + $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + } + + // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment) + $linkaddedforthirdparty=array(); + foreach ($this->amounts as $key => $value) + { + if ($mode == 'payment_sc') + { + $socialcontrib = new ChargeSociales($this->db); + $socialcontrib->fetch($key); + $result=$acc->add_url_line($bank_line_id, $socialcontrib->id, + DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc'); + if ($result <= 0) dol_print_error($this->db); + } + } + } + else + { + $this->error=$acc->error; + $error++; + } + } + + if (! $error) + { + return 1; + } + else + { + return -1; + } + } + + /** * \brief Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee * \param id_bank Id de la banque diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php index 62595972c7d..95355101001 100644 --- a/htdocs/fourn/facture/paiement.php +++ b/htdocs/fourn/facture/paiement.php @@ -48,12 +48,13 @@ $offset = $limit * $page ; if (! $sortorder) $sortorder="DESC"; if (! $sortfield) $sortfield="p.rowid"; +$amounts = array(); + // Security check $socid=0; if ($user->societe_id > 0) { - $action = ''; - $socid = $user->societe_id; + $socid = $user->societe_id; } @@ -64,130 +65,96 @@ if ($user->societe_id > 0) */ if ($action == 'add_paiement') { - $error = 0; + $error = 0; - $datepaye = dol_mktime(12, 0 , 0, - $_POST['remonth'], - $_POST['reday'], - $_POST['reyear']); - $paiement_id = 0; - $total = 0; - // Genere tableau des montants amounts - $amounts = array(); - foreach ($_POST as $key => $value) - { - if (substr($key,0,7) == 'amount_') - { - $other_facid = substr($key,7); - $amounts[$other_facid] = $_POST[$key]; - $total = $total + $amounts[$other_facid]; - } - } + $datepaye = dol_mktime(12, 0 , 0, + $_POST['remonth'], + $_POST['reday'], + $_POST['reyear']); + $paiement_id = 0; + $total = 0; + // Genere tableau des montants amounts + foreach ($_POST as $key => $value) + { + if (substr($key,0,7) == 'amount_') + { + $other_facid = substr($key,7); + $amounts[$other_facid] = $_POST[$key]; + $total = $total + $amounts[$other_facid]; + } + } - // Effectue les verifications des parametres - if ($_POST['paiementid'] <= 0) - { - $mesg = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'
'; - $error++; - } + // Effectue les verifications des parametres + if ($_POST['paiementid'] <= 0) + { + $mesg = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'
'; + $error++; + } - if ($conf->banque->enabled) - { - // Si module bank actif, un compte est obligatoire lors de la saisie - // d'un paiement - if (! $_POST['accountid']) - { - $mesg = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'
'; - $error++; - } - } + if ($conf->banque->enabled) + { + // Si module bank actif, un compte est obligatoire lors de la saisie + // d'un paiement + if (! $_POST['accountid']) + { + $mesg = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'
'; + $error++; + } + } - /* - \TODO A activer qd gestion avoir active et que creation facture fournisseur negative interdit - if ($total <= 0) - { - $mesg = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Amount')).'
'; - $error++; - } - */ + /* + \TODO A activer qd gestion avoir active et que creation facture fournisseur negative interdit + if ($total <= 0) + { + $mesg = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Amount')).'
'; + $error++; + } + */ - if (! $error) - { - $db->begin(); + if (! $error) + { + $db->begin(); - // Creation de la ligne paiement - $paiement = new PaiementFourn($db); - $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Array of amounts - $paiement->paiementid = $_POST['paiementid']; - $paiement->num_paiement = $_POST['num_paiement']; - $paiement->note = $_POST['comment']; + // Creation de la ligne paiement + $paiement = new PaiementFourn($db); + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; // Array of amounts + $paiement->paiementid = $_POST['paiementid']; + $paiement->num_paiement = $_POST['num_paiement']; + $paiement->note = $_POST['comment']; - $paiement_id = $paiement->create($user); - if ($paiement_id > 0) - { - if ($conf->banque->enabled) - { - // Insertion dans llx_bank - $label = "(SupplierInvoicePayment)"; - $acc = new Account($db, $_POST['accountid']); - //paiementid contient "CHQ ou VIR par exemple" - $bank_line_id = $acc->addline($paiement->datepaye, - $paiement->paiementid, - $label, - 0.0 - $paiement->total, - $paiement->num_paiement, - '', - $user); + if (! $error) + { + $paiement_id = $paiement->create($user); + if (! $paiement_id > 0) + { + $errmsg='
'.$paiement->error.'
'; + $error++; + } + } - // Mise a jour fk_bank dans llx_paiement. - // On connait ainsi le paiement qui a genere l'ecriture bancaire - if ($bank_line_id > 0) - { - $paiement->update_fk_bank($bank_line_id); - // Mise a jour liens (pour chaque facture concernees par le paiement) - foreach ($paiement->amounts as $key => $value) - { - $facid = $key; - $fac = new FactureFournisseur($db); - $fac->fetch($facid); - $fac->fetch_fournisseur(); - $acc->add_url_line($bank_line_id, - $paiement_id, - DOL_URL_ROOT.'/fourn/paiement/fiche.php?id=', - '(paiement)', - 'payment_supplier'); - $acc->add_url_line($bank_line_id, - $fac->fournisseur->id, - DOL_URL_ROOT.'/fourn/fiche.php?socid=', - $fac->fournisseur->nom, - 'company'); - } - } - else - { - $error++; - } - } - } - else - { - $mesg = '
'.$langs->trans($paiement->error).'
'; - $error++; - } + if (! $error) + { + $result=$paiement->addPaymentToBank($user,'payment_supplier','(SupplierInvoicePayment)',$_POST['accountid'],'',''); + if (! $result > 0) + { + $errmsg='
'.$paiement->error.'
'; + $error++; + } + } - if ($error == 0) - { - $loc = DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$paiement_id; - $db->commit(); - Header('Location: '.$loc); - exit; - } - else - { - $db->rollback(); - } - } + if (! $error) + { + $db->commit(); + $loc = DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$paiement_id; + Header('Location: '.$loc); + exit; + } + else + { + $db->rollback(); + } + } } /* @@ -204,159 +171,159 @@ if ($mesg) print $mesg; if ($action == 'create' || $action == 'add_paiement') { - $facture = new FactureFournisseur($db); - $facture->fetch($facid); + $facture = new FactureFournisseur($db); + $facture->fetch($facid); - $datefacture=dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); - $dateinvoice=($datefacture==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datefacture); + $datefacture=dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $dateinvoice=($datefacture==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datefacture); - $sql = 'SELECT s.nom, s.rowid as socid,'; - $sql.= ' f.rowid as ref, f.facnumber, f.amount, f.total_ttc as total'; - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user "; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn as f'; - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= ' WHERE f.fk_soc = s.rowid'; - $sql .= ' AND f.rowid = '.$facid; - if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - if ($num) - { - $obj = $db->fetch_object($resql); - $total = $obj->total; + $sql = 'SELECT s.nom, s.rowid as socid,'; + $sql.= ' f.rowid as ref, f.facnumber, f.amount, f.total_ttc as total'; + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user "; + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn as f'; + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ' WHERE f.fk_soc = s.rowid'; + $sql .= ' AND f.rowid = '.$facid; + if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num) + { + $obj = $db->fetch_object($resql); + $total = $obj->total; - print_fiche_titre($langs->trans('DoPayment')); + print_fiche_titre($langs->trans('DoPayment')); - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - print ''; + print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($conf->banque->enabled) - { - print ''; - } - else - { - print ''; - } - print '
'.$langs->trans('Payment').'
'.$langs->trans('Company').''.$obj->nom.'
'.$langs->trans('Date').''; - $html->select_date($dateinvoice,'','','','',"addpaiement",1,1); - print ''.$langs->trans('Comments').'
'.$langs->trans('PaymentMode').''; - $html->select_types_paiements(empty($_POST['paiementid'])?'':$_POST['paiementid'],'paiementid'); - print ''; - print '
'.$langs->trans('Numero').'
'.$langs->trans('Account').''; - $html->select_comptes(empty($_POST['accountid'])?'':$_POST['accountid'],'accountid',0,'',1); - print '
 
'; + print ''.$langs->trans('Payment').''; + print ''.$langs->trans('Company').''.$obj->nom.''; + print ''.$langs->trans('Date').''; + $html->select_date($dateinvoice,'','','','',"addpaiement",1,1); + print ''; + print ''.$langs->trans('Comments').''; + print ''.$langs->trans('PaymentMode').''; + $html->select_types_paiements(empty($_POST['paiementid'])?'':$_POST['paiementid'],'paiementid'); + print ''; + print ''; + print ''; + print ''.$langs->trans('Numero').''; + if ($conf->banque->enabled) + { + print ''.$langs->trans('Account').''; + $html->select_comptes(empty($_POST['accountid'])?'':$_POST['accountid'],'accountid',0,'',1); + print ''; + } + else + { + print ' '; + } + print ''; - /* - * Autres factures impayees - */ - $sql = 'SELECT f.rowid as facid,f.rowid as ref,f.facnumber,f.total_ttc, f.datef as df'; - $sql .= ', sum(pf.amount) as am'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; - $sql .= ' WHERE f.fk_soc = '.$facture->socid; - $sql .= ' AND f.paye = 0'; - $sql .= ' AND f.fk_statut = 1'; // Statut=0 => non validee, Statut=2 => annulee - $sql .= ' GROUP BY f.rowid,f.facnumber,f.total_ttc,f.datef'; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - if ($num > 0) - { - $i = 0; - print '
'; + /* + * Autres factures impayees + */ + $sql = 'SELECT f.rowid as facid,f.rowid as ref,f.facnumber,f.total_ttc, f.datef as df'; + $sql .= ', sum(pf.amount) as am'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; + $sql .= ' WHERE f.fk_soc = '.$facture->socid; + $sql .= ' AND f.paye = 0'; + $sql .= ' AND f.fk_statut = 1'; // Statut=0 => non validee, Statut=2 => annulee + $sql .= ' GROUP BY f.rowid,f.facnumber,f.total_ttc,f.datef'; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num > 0) + { + $i = 0; + print '
'; - print $langs->trans('Invoices').'
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print $langs->trans('Invoices').'
'; + print '
'.$langs->trans('Ref').''.$langs->trans('RefSupplier').''.$langs->trans('Date').''.$langs->trans('AmountTTC').''.$langs->trans('AlreadyPaid').''.$langs->trans('RemainderToPay').''.$langs->trans('Amount').'
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - $var=True; - $total=0; - $totalrecu=0; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $var=!$var; - print ''; - print ''; - print ''; - if ($objp->df > 0 ) - { - print ''; - } - else - { - print ''; - } - print ''; - print ''; - print ''; - print '\n"; - $total+=$objp->total; - $total_ttc+=$objp->total_ttc; - $totalrecu+=$objp->am; - $i++; - } - if ($i > 1) - { - // Print total - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - print "
'.$langs->trans('Ref').''.$langs->trans('RefSupplier').''.$langs->trans('Date').''.$langs->trans('AmountTTC').''.$langs->trans('AlreadyPaid').''.$langs->trans('RemainderToPay').''.$langs->trans('Amount').'
'.img_object($langs->trans('ShowBill'),'bill').' '.$objp->ref; - print ''.$objp->facnumber.''; - print dol_print_date($db->jdate($objp->df)).'!!!'.price($objp->total_ttc).''.price($objp->am).''.price($objp->total_ttc - $objp->am).''; - $namef = 'amount_'.$objp->facid; - print ''; - print "
'.$langs->trans('TotalTTC').':'.price($total_ttc).''.price($totalrecu).''.price($total_ttc - $totalrecu).' 
\n"; - } - $db->free($resql); - } - else - { - dol_print_error($db); - } + $var=True; + $total=0; + $totalrecu=0; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + print ''; + print ''.img_object($langs->trans('ShowBill'),'bill').' '.$objp->ref; + print ''; + print ''.$objp->facnumber.''; + if ($objp->df > 0 ) + { + print ''; + print dol_print_date($db->jdate($objp->df)).''; + } + else + { + print '!!!'; + } + print ''.price($objp->total_ttc).''; + print ''.price($objp->am).''; + print ''.price($objp->total_ttc - $objp->am).''; + print ''; + $namef = 'amount_'.$objp->facid; + print ''; + print "\n"; + $total+=$objp->total; + $total_ttc+=$objp->total_ttc; + $totalrecu+=$objp->am; + $i++; + } + if ($i > 1) + { + // Print total + print ''; + print ''.$langs->trans('TotalTTC').':'; + print ''.price($total_ttc).''; + print ''.price($totalrecu).''; + print ''.price($total_ttc - $totalrecu).''; + print ' '; + print "\n"; + } + print "\n"; + } + $db->free($resql); + } + else + { + dol_print_error($db); + } - /* - * - */ + /* + * + */ - print '
'; - print '
'; + print '
'; + print '
'; - print '
'; - } - } + print ''; + } + } } /* @@ -364,147 +331,147 @@ if ($action == 'create' || $action == 'add_paiement') */ if (! $_GET['action'] && ! $_POST['action']) { - if ($page == -1) $page = 0 ; - $limit = $conf->liste_limit; - $offset = $limit * $page ; + if ($page == -1) $page = 0 ; + $limit = $conf->liste_limit; + $offset = $limit * $page ; - if (! $sortorder) $sortorder='DESC'; - if (! $sortfield) $sortfield='p.datep'; + if (! $sortorder) $sortorder='DESC'; + if (! $sortfield) $sortfield='p.datep'; - $sql = 'SELECT p.rowid, p.rowid as pid, p.datep as dp, p.amount as pamount,'; - $sql.= ' f.rowid as facid, f.rowid as ref, f.facnumber, f.amount,'; - $sql.= ' s.rowid as socid, s.nom,'; - $sql.= ' c.libelle as paiement_type, p.num_paiement,'; - $sql.= ' ba.rowid as bid, ba.label'; - if (!$user->rights->societe->client->voir) $sql .= ", sc.fk_soc, sc.fk_user "; - $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p'; - if (!$user->rights->societe->client->voir) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn '; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.rowid = f.fk_soc'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; - $sql.= ' WHERE 1=1'; - if (!$user->rights->societe->client->voir) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - if ($socid) - { - $sql .= ' AND f.fk_soc = '.$socid; - } - // Search criteria - if ($_REQUEST["search_ref"]) - { - $sql .=" AND p.rowid=".$_REQUEST["search_ref"]; - } + $sql = 'SELECT p.rowid, p.rowid as pid, p.datep as dp, p.amount as pamount,'; + $sql.= ' f.rowid as facid, f.rowid as ref, f.facnumber, f.amount,'; + $sql.= ' s.rowid as socid, s.nom,'; + $sql.= ' c.libelle as paiement_type, p.num_paiement,'; + $sql.= ' ba.rowid as bid, ba.label'; + if (!$user->rights->societe->client->voir) $sql .= ", sc.fk_soc, sc.fk_user "; + $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p'; + if (!$user->rights->societe->client->voir) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn '; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.rowid = f.fk_soc'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; + $sql.= ' WHERE 1=1'; + if (!$user->rights->societe->client->voir) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + if ($socid) + { + $sql .= ' AND f.fk_soc = '.$socid; + } + // Search criteria + if ($_REQUEST["search_ref"]) + { + $sql .=" AND p.rowid=".$_REQUEST["search_ref"]; + } if ($_REQUEST["search_account"]) { $sql .=" AND b.fk_account=".$_REQUEST["search_account"]; } - if ($_REQUEST["search_paymenttype"]) + if ($_REQUEST["search_paymenttype"]) { $sql .=" AND c.code='".$_REQUEST["search_paymenttype"]."'"; } - if ($_REQUEST["search_amount"]) - { - $sql .=" AND p.amount=".price2num($_REQUEST["search_amount"]); - } - if ($_REQUEST["search_company"]) - { - $sql .=" AND s.nom LIKE '%".addslashes($_REQUEST["search_company"])."%'"; - } - $sql.= $db->order($sortfield,$sortorder); - $sql.= $db->plimit($limit + 1 ,$offset); + if ($_REQUEST["search_amount"]) + { + $sql .=" AND p.amount=".price2num($_REQUEST["search_amount"]); + } + if ($_REQUEST["search_company"]) + { + $sql .=" AND s.nom LIKE '%".addslashes($_REQUEST["search_company"])."%'"; + } + $sql.= $db->order($sortfield,$sortorder); + $sql.= $db->plimit($limit + 1 ,$offset); - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - $var=True; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + $var=True; - $paramlist=''; - $paramlist.=($_REQUEST["search_ref"]?"&search_ref=".$_REQUEST["search_ref"]:""); - $paramlist.=($_REQUEST["search_company"]?"&search_company=".$_REQUEST["search_company"]:""); - $paramlist.=($_REQUEST["search_amount"]?"&search_amount=".$_REQUEST["search_amount"]:""); + $paramlist=''; + $paramlist.=($_REQUEST["search_ref"]?"&search_ref=".$_REQUEST["search_ref"]:""); + $paramlist.=($_REQUEST["search_company"]?"&search_company=".$_REQUEST["search_company"]:""); + $paramlist.=($_REQUEST["search_amount"]?"&search_amount=".$_REQUEST["search_amount"]:""); - print_barre_liste($langs->trans('SupplierPayments'), $page, 'paiement.php',$paramlist,$sortfield,$sortorder,'',$num); + print_barre_liste($langs->trans('SupplierPayments'), $page, 'paiement.php',$paramlist,$sortfield,$sortorder,'',$num); - print '
'; - print ''; - print ''; - print_liste_field_titre($langs->trans('RefPayment'),'paiement.php','p.rowid','',$paramlist,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Date'),'paiement.php','dp','',$paramlist,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('ThirdParty'),'paiement.php','s.nom','',$paramlist,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Type'),'paiement.php','c.libelle','',$paramlist,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Account'),'paiement.php','ba.label','',$paramlist,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Amount'),'paiement.php','f.amount','',$paramlist,'align="right"',$sortfield,$sortorder); - //print_liste_field_titre($langs->trans('Invoice'),'paiement.php','facnumber','',$paramlist,'',$sortfield,$sortorder); - print "\n"; + print ''; + print '
'; + print ''; + print_liste_field_titre($langs->trans('RefPayment'),'paiement.php','p.rowid','',$paramlist,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('Date'),'paiement.php','dp','',$paramlist,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('ThirdParty'),'paiement.php','s.nom','',$paramlist,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('Type'),'paiement.php','c.libelle','',$paramlist,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('Account'),'paiement.php','ba.label','',$paramlist,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('Amount'),'paiement.php','f.amount','',$paramlist,'align="right"',$sortfield,$sortorder); + //print_liste_field_titre($langs->trans('Invoice'),'paiement.php','facnumber','',$paramlist,'',$sortfield,$sortorder); + print "\n"; - // Lines for filters fields - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; print ''; - print ''; - print "\n"; + print ''; + print ''; + print "\n"; - while ($i < min($num,$limit)) - { - $objp = $db->fetch_object($resql); - $var=!$var; - print ''; + while ($i < min($num,$limit)) + { + $objp = $db->fetch_object($resql); + $var=!$var; + print ''; - // Ref payment - print ''; + // Ref payment + print ''; - // Date - print '\n"; + // Date + print '\n"; - print ''; + print ''; - print '\n"; + print '\n"; - print ''; + print ''; - print ''; + print ''; - // Ref invoice - /*$invoicesupplierstatic->ref=$objp->facnumber; - $invoicesupplierstatic->id=$objp->facid; - print '';*/ + // Ref invoice + /*$invoicesupplierstatic->ref=$objp->facnumber; + $invoicesupplierstatic->id=$objp->facid; + print '';*/ - print ''; - $i++; - } - print "
'; - print ''; - print ' '; - print ''; - print ''; + // Lines for filters fields + print '
'; + print ''; + print ' '; + print ''; + print ''; $html->select_types_paiements($_REQUEST["search_paymenttype"],'search_paymenttype','',2,1,1); print ''; $html->select_comptes($_REQUEST["search_account"],'search_account',0,'',1); - print ''; - print ''; - print ''; - print '
'; + print ''; + print ''; + print '
'.img_object($langs->trans('ShowPayment'),'payment').' '.$objp->pid.''.img_object($langs->trans('ShowPayment'),'payment').' '.$objp->pid.''.dol_print_date($db->jdate($objp->dp),'day')."'.dol_print_date($db->jdate($objp->dp),'day')."'; - if ($objp->socid) print ''.img_object($langs->trans('ShowCompany'),'company').' '.dol_trunc($objp->nom,32).''; - else print ' '; - print ''; + if ($objp->socid) print ''.img_object($langs->trans('ShowCompany'),'company').' '.dol_trunc($objp->nom,32).''; + else print ' '; + print ''.dol_trunc($objp->paiement_type.' '.$objp->num_paiement,32)."'.dol_trunc($objp->paiement_type.' '.$objp->num_paiement,32)."'; - if ($objp->bid) print ''.img_object($langs->trans("ShowAccount"),'account').' '.dol_trunc($objp->label,24).''; - else print ' '; - print ''; + if ($objp->bid) print ''.img_object($langs->trans("ShowAccount"),'account').' '.dol_trunc($objp->label,24).''; + else print ' '; + print ''.price($objp->pamount).''.price($objp->pamount).''; - print $invoicesupplierstatic->getNomUrl(1); - print ''; + print $invoicesupplierstatic->getNomUrl(1); + print '
"; - print "
\n"; - } - else - { - dol_print_error($db); - } + print ''; + $i++; + } + print ""; + print "\n"; + } + else + { + dol_print_error($db); + } } $db->close();