From a0051a856a93967f881e9e2ea61fdf0fb6e8a3b4 Mon Sep 17 00:00:00 2001 From: gauthier Date: Wed, 15 Jun 2016 17:10:42 +0200 Subject: [PATCH 1/3] NEW : conf to allow payments on different thirdparties bills but same parent company --- htdocs/admin/facture.php | 32 ++++++++++++++++++++++++++++++++ htdocs/compta/paiement.php | 23 +++++++++++++++++++---- htdocs/langs/en_US/bills.lang | 1 + 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index bae4b0abd88..20d2ade591c 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -280,6 +280,24 @@ if ($action == 'set_INVOICE_AUTO_FILLJS') } } +if ($action == 'set_FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS') +{ + $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS'); // No alpha here, we want exact string + + $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$freetext,'chaine',0,'',$conf->entity); + + if (! $res > 0) $error++; + + if (! $error) + { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + setEventMessages($langs->trans("Error"), null, 'errors'); + } +} + /* * View @@ -764,6 +782,20 @@ print '\n"; print ''; +// Add js auto fill amount on paiement form +$var=! $var; +print '
'; +print ''; +print ''; +print ''; +print $langs->trans("PaymentOnDifferentThirdBills"); +print ''; +print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS,1); +print ''; +print ''; +print "\n"; +print '
'; + $var=! $var; print '
'; print ''; diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index fa1341dcbc6..8bd38593440 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -33,6 +33,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $langs->load('companies'); $langs->load('bills'); @@ -518,11 +519,21 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie * List of unpaid invoices */ $sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.multicurrency_total_ttc, f.type, '; - $sql.= ' f.datef as df'; + $sql.= ' f.datef as df, f.fk_soc as socid'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; - $sql.= ' WHERE f.entity = '.$conf->entity; - $sql.= ' AND f.fk_soc = '.$facture->socid; - $sql.= ' AND f.paye = 0'; + + if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)'; + } + + $sql.= ' WHERE f.entity = '.$conf->entity; + $sql.= ' AND (f.fk_soc = '.$facture->socid; + + if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { + $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = (SELECT parent FROM '.MAIN_DB_PREFIX.'societe WHERE rowid = '.$facture->socid.'))'; + } + + $sql.= ') AND f.paye = 0'; $sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled if ($facture->type != 2) { @@ -583,6 +594,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $objp = $db->fetch_object($resql); $var=!$var; + $soc = new Societe($db); + $soc->fetch($objp->socid); + $invoice=new Facture($db); $invoice->fetch($objp->facid); $paiement = $invoice->getSommePaiement(); @@ -605,6 +619,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; print $invoice->getNomUrl(1,''); + if($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' '; print "\n"; // Date diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index f6428f6a49a..6f0b1217f6d 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -311,6 +311,7 @@ LatestRelatedBill=Latest related invoice WarningBillExist=Warning, one or more invoice already exist MergingPDFTool=Merging PDF tool AmountPaymentDistributedOnInvoice=Payment amount distributed on invoice +PaymentOnDifferentThirdBills=Allow payments on different thirdparties bills but same parent company PaymentNote=Payment note ListOfPreviousSituationInvoices=List of previous situation invoices ListOfNextSituationInvoices=List of next situation invoices From b8f51753438fb26c1333a7e471a2216489736033 Mon Sep 17 00:00:00 2001 From: gauthier Date: Wed, 15 Jun 2016 17:16:16 +0200 Subject: [PATCH 2/3] FIX : sql optimisation --- htdocs/compta/paiement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 8bd38593440..a9414fcafeb 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -530,7 +530,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $sql.= ' AND (f.fk_soc = '.$facture->socid; if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { - $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = (SELECT parent FROM '.MAIN_DB_PREFIX.'societe WHERE rowid = '.$facture->socid.'))'; + $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')'; } $sql.= ') AND f.paye = 0'; From 427695d8692ae5e724165caae4b4168e23407071 Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 17 Jun 2016 17:26:49 +0200 Subject: [PATCH 3/3] FIX : New conf must be in payments tab --- htdocs/admin/facture.php | 32 ------------------------------ htdocs/admin/payment.php | 43 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index 20d2ade591c..bae4b0abd88 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -280,24 +280,6 @@ if ($action == 'set_INVOICE_AUTO_FILLJS') } } -if ($action == 'set_FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS') -{ - $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS'); // No alpha here, we want exact string - - $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$freetext,'chaine',0,'',$conf->entity); - - if (! $res > 0) $error++; - - if (! $error) - { - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - setEventMessages($langs->trans("Error"), null, 'errors'); - } -} - /* * View @@ -782,20 +764,6 @@ print '\n"; print ''; -// Add js auto fill amount on paiement form -$var=! $var; -print '
'; -print ''; -print ''; -print ''; -print $langs->trans("PaymentOnDifferentThirdBills"); -print ''; -print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS,1); -print ''; -print ''; -print "\n"; -print '
'; - $var=! $var; print '
'; print ''; diff --git a/htdocs/admin/payment.php b/htdocs/admin/payment.php index fa99e2c202b..8ce904aad7c 100644 --- a/htdocs/admin/payment.php +++ b/htdocs/admin/payment.php @@ -69,7 +69,23 @@ if ($action == 'setmod') dolibarr_set_const($db, "PAYMENT_ADDON",$value,'chaine',0,'',$conf->entity); } +if ($action == 'set_FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS') +{ + $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS'); // No alpha here, we want exact string + $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$freetext,'chaine',0,'',$conf->entity); + + if (! $res > 0) $error++; + + if (! $error) + { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + setEventMessages($langs->trans("Error"), null, 'errors'); + } +} /* * View @@ -215,6 +231,33 @@ foreach ($dirmodels as $reldir) print ''; +print "
"; + +print load_fiche_titre($langs->trans("OtherOptions"),'',''); + +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +// Allow payments on different thirdparties bills but same parent company +$var=! $var; +print ''; +print ''; +print ''; +print '\n"; +print ''; + +print '
'.$langs->trans("Parameter").''.$langs->trans("Value").' 
'; +print $langs->trans("PaymentOnDifferentThirdBills"); +print ''; +print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS,1); +print ''; +print ''; +print "
'; + dol_fiche_end();