From 5803087d4f1775e40dbc08fd403e6d190a270b5e Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 7 Oct 2016 14:32:27 +0200 Subject: [PATCH] NEW : concat of all invoice pdf if invoice validation --- htdocs/commande/list.php | 58 ++++++++++++++++++++++++++++++----- htdocs/langs/en_US/bills.lang | 1 + 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index d157057b016..35ea4489cff 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -209,7 +209,10 @@ if($massaction == 'confirm_createbills') { $orders = GETPOST('toselect'); $createbills_onebythird = GETPOST('createbills_onebythird', 'int'); - $TOrderTMP = array(); + $validate_invoices = GETPOST('valdate_invoices', 'int'); + + $TFact = array(); + $TFactThird = array(); $nb_bills_created = 0; @@ -221,7 +224,7 @@ if($massaction == 'confirm_createbills') { if($cmd->fetch($id_order) <= 0) continue; $object = new Facture($db); - if(!empty($createbills_onebythird) && !empty($TOrderTMP[$cmd->socid])) $object = &$TOrderTMP[$cmd->socid]; // To use only one bill for a third + if(!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $object = $TFactThird[$cmd->socid]; // To use only one bill for a third else { $object->socid = $cmd->socid; @@ -240,7 +243,9 @@ if($massaction == 'confirm_createbills') { $object->origin = 'commande'; $object->origin_id = $id_order; - if($object->create($user)) $nb_bills_created++; + $res = $object->create($user); + + if($res > 0) $nb_bills_created++; } @@ -369,12 +374,40 @@ if($massaction == 'confirm_createbills') { } } - + $cmd->classifyBilled($user); - - if(!empty($createbills_onebythird) && empty($TOrderTMP[$cmd->socid])) $TOrderTMP[$cmd->socid] = $object; - } + if(!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $object; + else $TFact[$object->id] = $object; + } + + // Build doc with all invoices + $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird; + $toselect = array(); + + if(!empty($validate_invoices)) { + + $massaction = $action = 'builddoc'; + + foreach($TAllFact as &$object) { + $object->validate($user); + $toselect[] = $object->id; // For builddoc action + + // Fac builddoc + $upload_dir = $conf->facture->dir_output; + $permissioncreate=$user->rights->facture->creer; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + } + + $objectclass='Facture'; + $objectlabel='Invoice'; + $permtoread = $user->rights->facture->lire; + $permtodelete = $user->rights->facture->supprimer; + $uploaddir = $conf->facture->dir_output; + include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + + } + if (! $error) { $db->commit(); @@ -591,6 +624,7 @@ if ($resql) if ($search_total_ttc != '') $param.='&search_total_ttc='.$search_total_ttc; if ($show_files) $param.='&show_files=' .$show_files; if ($optioncss != '') $param.='&optioncss='.$optioncss; + if ($billed != '') $param.='&billed='.$billed; // Add $param from extra fields foreach ($search_array_options as $key => $val) { @@ -727,7 +761,7 @@ if ($resql) print $langs->trans('DateInvoice'); print ''; print ''; - print $form->select_date('', '', '', '', '', "addprop", 1, 1); + print $form->select_date('', '', '', '', '', '', 1, 1); print ''; print ''; print ''; @@ -738,6 +772,14 @@ if ($resql) print $form->selectyesno('createbills_onebythird', '', 1); print ''; print ''; + print ''; + print ''; + print $langs->trans('ValidateInvoices'); + print ''; + print ''; + print $form->selectyesno('valdate_invoices', 1, 1); + print ''; + print ''; print ''; print '
'; diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index deee06e3690..3f23893855c 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -421,6 +421,7 @@ ShowUnpaidAll=Show all unpaid invoices ShowUnpaidLateOnly=Show late unpaid invoices only PaymentInvoiceRef=Payment invoice %s ValidateInvoice=Validate invoice +ValidateInvoices=Validate invoices Cash=Cash Reported=Delayed DisabledBecausePayments=Not possible since there are some payments