From 2642e1d1b38af42409ebdfc57067ea7a519ac21a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 23 Feb 2021 15:35:16 +0100 Subject: [PATCH] Code syntax --- htdocs/compta/facture/card.php | 695 +++++++++++++-------------------- 1 file changed, 281 insertions(+), 414 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 41178def47d..62a40082a78 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -50,8 +50,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; -if (!empty($conf->commande->enabled)) +if (!empty($conf->commande->enabled)) { require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; +} if (!empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; @@ -154,12 +155,9 @@ $parameters = array('socid' => $socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -if (empty($reshook)) -{ - if ($cancel) - { - if (!empty($backtopage)) - { +if (empty($reshook)) { + if ($cancel) { + if (!empty($backtopage)) { header("Location: ".$backtopage); exit; } @@ -173,8 +171,7 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once // Action clone object - if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) - { + if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) { $objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone. We use native clone to keep this->db valid. $objectutil->date = dol_mktime(12, 0, 0, GETPOST('newdatemonth', 'int'), GETPOST('newdateday', 'int'), GETPOST('newdateyear', 'int')); @@ -230,8 +227,7 @@ if (empty($reshook)) } } } // Delete line - elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) - { + elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) { $object->fetch($id); $object->fetch_thirdparty(); @@ -262,14 +258,12 @@ if (empty($reshook)) $action = ''; } } // Delete link of credit note to invoice - elseif ($action == 'unlinkdiscount' && $usercancreate) - { + elseif ($action == 'unlinkdiscount' && $usercancreate) { $discount = new DiscountAbsolute($db); $result = $discount->fetch(GETPOST("discountid")); $discount->unlink_invoice(); } // Validation - elseif ($action == 'valid' && $usercancreate) - { + elseif ($action == 'valid' && $usercancreate) { $object->fetch($id); // On verifie signe facture @@ -306,13 +300,11 @@ if (empty($reshook)) } //var_dump($array_of_total_ht_per_vat_rate);exit; - foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) - { + foreach ($array_of_total_ht_per_vat_rate as $vatrate => $tmpvalue) { $tmp_total_ht = $array_of_total_ht_per_vat_rate[$vatrate]; $tmp_total_ht_devise = $array_of_total_ht_devise_per_vat_rate[$vatrate]; - if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) - { + if (($tmp_total_ht < 0 || $tmp_total_ht_devise < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) { if ($object->type == $object::TYPE_DEPOSIT) { $langs->load("errors"); // Using negative lines on deposit lead to headach and blocking problems when you want to consume them. @@ -335,18 +327,15 @@ if (empty($reshook)) } } - elseif ($action == 'classin' && $usercancreate) - { + elseif ($action == 'classin' && $usercancreate) { $object->fetch($id); $object->setProject($_POST['projectid']); - } elseif ($action == 'setmode' && $usercancreate) - { + } elseif ($action == 'setmode' && $usercancreate) { $object->fetch($id); $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); if ($result < 0) dol_print_error($db, $object->error); - } elseif ($action == 'setretainedwarrantyconditions' && $user->rights->facture->creer) - { + } elseif ($action == 'setretainedwarrantyconditions' && $user->rights->facture->creer) { $object->fetch($id); $object->retained_warranty_fk_cond_reglement = 0; // To clean property $result = $object->setRetainedWarrantyPaymentTerms(GETPOST('retained_warranty_fk_cond_reglement', 'int')); @@ -368,11 +357,9 @@ if (empty($reshook)) $result = $object->setRetainedWarrantyDateLimit(GETPOST('retained_warranty_date_limit', 'float')); if ($result < 0) dol_print_error($db, $object->error); - } // Multicurrency Code - elseif ($action == 'setmulticurrencycode' && $usercancreate) { + } elseif ($action == 'setmulticurrencycode' && $usercancreate) { // Multicurrency Code $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); - } // Multicurrency rate - elseif ($action == 'setmulticurrencyrate' && $usercancreate) { + } elseif ($action == 'setmulticurrencyrate' && $usercancreate) { // Multicurrency rate $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int')); } elseif ($action == 'setinvoicedate' && $usercancreate) { $object->fetch($id); @@ -400,8 +387,7 @@ if (empty($reshook)) if ($result < 0) { dol_print_error($db, $object->error); } - } elseif ($action == 'setconditions' && $usercancreate) - { + } elseif ($action == 'setconditions' && $usercancreate) { $object->fetch($id); $object->cond_reglement_code = 0; // To clean property $object->cond_reglement_id = 0; // To clean property @@ -435,8 +421,7 @@ if (empty($reshook)) } else { $db->commit(); } - } elseif ($action == 'setpaymentterm' && $usercancreate) - { + } elseif ($action == 'setpaymentterm' && $usercancreate) { $object->fetch($id); $object->date_lim_reglement = dol_mktime(12, 0, 0, $_POST['paymenttermmonth'], $_POST['paymenttermday'], $_POST['paymenttermyear']); if ($object->date_lim_reglement < $object->date) { @@ -447,8 +432,7 @@ if (empty($reshook)) if ($result < 0) { dol_print_error($db, $object->error); } - } elseif ($action == 'setrevenuestamp' && $usercancreate) - { + } elseif ($action == 'setrevenuestamp' && $usercancreate) { $object->fetch($id); $object->revenuestamp = GETPOST('revenuestamp'); $result = $object->update($user); @@ -475,11 +459,9 @@ if (empty($reshook)) if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } } - } // Set incoterm - elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) { + } elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) { // Set incoterm $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); - } // bank account - elseif ($action == 'setbankaccount' && $usercancreate) { + } elseif ($action == 'setbankaccount' && $usercancreate) { // bank account $result = $object->setBankAccount(GETPOST('fk_account', 'int')); } elseif ($action == 'setremisepercent' && $usercancreate) { $object->fetch($id); @@ -500,8 +482,7 @@ if (empty($reshook)) } } // We use the credit to reduce remain to pay - if (GETPOST("remise_id_for_payment", 'int') > 0) - { + if (GETPOST("remise_id_for_payment", 'int') > 0) { require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; $discount = new DiscountAbsolute($db); $discount->fetch(GETPOST("remise_id_for_payment", 'int')); @@ -515,8 +496,7 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorDiscountLargerThanRemainToPaySplitItBefore"), null, 'errors'); } - if (!$error) - { + if (!$error) { $result = $discount->link_to_invoice(0, $id); if ($result < 0) { setEventMessages($discount->error, $discount->errors, 'errors'); @@ -524,8 +504,7 @@ if (empty($reshook)) } } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); @@ -539,12 +518,10 @@ if (empty($reshook)) $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'setref' && $usercancreate) - { + } elseif ($action == 'setref' && $usercancreate) { $object->fetch($id); $object->setValueFrom('ref', GETPOST('ref'), '', null, '', '', $user, 'BILL_MODIFY'); - } elseif ($action == 'setref_client' && $usercancreate) - { + } elseif ($action == 'setref_client' && $usercancreate) { $object->fetch($id); $object->set_ref_client(GETPOST('ref_client')); } // Classify to validated @@ -559,16 +536,13 @@ if (empty($reshook)) // Check for mandatory fields in thirdparty (defined into setup) $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL'); - foreach ($array_to_check as $key) - { + foreach ($array_to_check as $key) { $keymin = strtolower($key); $i = (int) preg_replace('/[^0-9]/', '', $key); $vallabel = $object->thirdparty->$keymin; - if ($i > 0) - { - if ($object->thirdparty->isACompany()) - { + if ($i > 0) { + if ($object->thirdparty->isACompany()) { // Check for mandatory prof id (but only if country is other than ours) if ($mysoc->country_id > 0 && $object->thirdparty->country_id == $mysoc->country_id) { @@ -583,11 +557,9 @@ if (empty($reshook)) } } else { //var_dump($conf->global->SOCIETE_EMAIL_MANDATORY); - if ($key == 'EMAIL') - { + if ($key == 'EMAIL') { // Check for mandatory - if (!empty($conf->global->SOCIETE_EMAIL_INVOICE_MANDATORY) && !isValidEMail($object->thirdparty->email)) - { + if (!empty($conf->global->SOCIETE_EMAIL_INVOICE_MANDATORY) && !isValidEMail($object->thirdparty->email)) { $langs->load("errors"); $error++; setEventMessages($langs->trans("ErrorBadEMail", $object->thirdparty->email).' ('.$langs->trans("ForbiddenBySetupRules").')', null, 'errors'); @@ -598,15 +570,13 @@ if (empty($reshook)) // Check for mandatory fields in invoice $array_to_check = array('REF_CUSTOMER'=>'RefCustomer'); - foreach ($array_to_check as $key => $val) - { + foreach ($array_to_check as $key => $val) { $keymin = strtolower($key); $vallabel = $object->$keymin; // Check for mandatory $keymandatory = 'INVOICE_'.$key.'_MANDATORY_FOR_VALIDATION'; - if (!$vallabel && !empty($conf->global->$keymandatory)) - { + if (!$vallabel && !empty($conf->global->$keymandatory)) { $langs->load("errors"); $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val)), null, 'errors'); @@ -614,8 +584,7 @@ if (empty($reshook)) } // Check for warehouse - if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) - { + if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) { $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); @@ -623,8 +592,7 @@ if (empty($reshook)) $qualified_for_stock_change = $object->hasProductsOrServices(1); } - if ($qualified_for_stock_change) - { + if ($qualified_for_stock_change) { if (!$idwarehouse || $idwarehouse == - 1) { $error++; setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); @@ -633,11 +601,9 @@ if (empty($reshook)) } } - if (!$error) - { + if (!$error) { $result = $object->validate($user, '', $idwarehouse); - if ($result >= 0) - { + if ($result >= 0) { // Define output language if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { @@ -663,16 +629,14 @@ if (empty($reshook)) } } } // Go back to draft status (unvalidate) - elseif ($action == 'confirm_modif' && $usercanunvalidate) - { + elseif ($action == 'confirm_modif' && $usercanunvalidate) { $idwarehouse = GETPOST('idwarehouse', 'int'); $object->fetch($id); $object->fetch_thirdparty(); // Check parameters - if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) - { + if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) { $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); @@ -680,8 +644,7 @@ if (empty($reshook)) $qualified_for_stock_change = $object->hasProductsOrServices(1); } - if ($qualified_for_stock_change) - { + if ($qualified_for_stock_change) { if (!$idwarehouse || $idwarehouse == - 1) { $error++; setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); @@ -716,16 +679,13 @@ if (empty($reshook)) $ventilExportCompta = $object->getVentilExportCompta(); // On verifie si aucun paiement n'a ete effectue - if ($ventilExportCompta == 0) - { - if (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_EDITED) || ($resteapayer == $object->total_ttc && empty($object->paye))) - { + if ($ventilExportCompta == 0) { + if (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_EDITED) || ($resteapayer == $object->total_ttc && empty($object->paye))) { $result = $object->setDraft($user, $idwarehouse); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); @@ -744,14 +704,12 @@ if (empty($reshook)) } } } // Classify "paid" - elseif ($action == 'confirm_paid' && $confirm == 'yes' && $usercanissuepayment) - { + elseif ($action == 'confirm_paid' && $confirm == 'yes' && $usercanissuepayment) { $object->fetch($id); $result = $object->setPaid($user); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } // Classif "paid partialy" - elseif ($action == 'confirm_paid_partially' && $confirm == 'yes' && $usercanissuepayment) - { + elseif ($action == 'confirm_paid_partially' && $confirm == 'yes' && $usercanissuepayment) { $object->fetch($id); $close_code = GETPOST("close_code", 'restricthtml'); $close_note = GETPOST("close_note", 'restricthtml'); @@ -773,8 +731,7 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), null, 'errors'); } } // Convertir en reduc - elseif ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $usercancreate) - { + elseif ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $usercancreate) { $object->fetch($id); $object->fetch_thirdparty(); //$object->fetch_lines(); // Already done into fetch @@ -786,8 +743,8 @@ if (empty($reshook)) $canconvert = 0; if ($object->type == Facture::TYPE_DEPOSIT && empty($discountcheck->id)) $canconvert = 1; // we can convert deposit into discount if deposit is payed (completely, partially or not at all) and not already converted (see real condition into condition used to show button converttoreduc) if (($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_SITUATION) && $object->paye == 0 && empty($discountcheck->id)) $canconvert = 1; // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc) - if ($canconvert) - { + + if ($canconvert) { $db->begin(); $amount_ht = $amount_tva = $amount_ttc = array(); @@ -795,10 +752,8 @@ if (empty($reshook)) // Loop on each vat rate $i = 0; - foreach ($object->lines as $line) - { - if ($line->product_type < 9 && $line->total_ht != 0) // Remove lines with product_type greater than or equal to 9 and no need to create discount if amount is null - { + foreach ($object->lines as $line) { + if ($line->product_type < 9 && $line->total_ht != 0) { // Remove lines with product_type greater than or equal to 9 and no need to create discount if amount is null $keyforvatrate = $line->tva_tx.($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''); $amount_ht[$keyforvatrate] += $line->total_ht; @@ -830,13 +785,13 @@ if (empty($reshook)) // Insert one discount by VAT rate category $discount = new DiscountAbsolute($db); - if ($object->type == Facture::TYPE_CREDIT_NOTE) + if ($object->type == Facture::TYPE_CREDIT_NOTE) { $discount->description = '(CREDIT_NOTE)'; - elseif ($object->type == Facture::TYPE_DEPOSIT) + } elseif ($object->type == Facture::TYPE_DEPOSIT) { $discount->description = '(DEPOSIT)'; - elseif ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_SITUATION) + } elseif ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_SITUATION) { $discount->description = '(EXCESS RECEIVED)'; - else { + } else { setEventMessages($langs->trans('CantConvertToReducAnInvoiceOfThisType'), null, 'errors'); } $discount->fk_soc = $object->socid; @@ -844,8 +799,7 @@ if (empty($reshook)) $error = 0; - if ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_SITUATION) - { + if ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_SITUATION) { // If we're on a standard invoice, we have to get excess received to create a discount in TTC without VAT // Total payments @@ -872,7 +826,9 @@ if (empty($reshook)) while ($obj = $db->fetch_object($resql)) { $total_creditnote_and_deposit += $obj->amount_ttc; } - } else dol_print_error($db); + } else { + dol_print_error($db); + } $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc; $discount->amount_tva = 0; @@ -880,15 +836,12 @@ if (empty($reshook)) $discount->vat_src_code = ''; $result = $discount->create($user); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) - { - foreach ($amount_ht as $tva_tx => $xxx) - { + if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { + foreach ($amount_ht as $tva_tx => $xxx) { $discount->amount_ht = abs($amount_ht[$tva_tx]); $discount->amount_tva = abs($amount_tva[$tva_tx]); $discount->amount_ttc = abs($amount_ttc[$tva_tx]); @@ -909,21 +862,18 @@ if (empty($reshook)) $discount->vat_src_code = $vat_src_code; $result = $discount->create($user); - if ($result < 0) - { + if ($result < 0) { $error++; break; } } } - if (empty($error)) - { + if (empty($error)) { if ($object->type != Facture::TYPE_DEPOSIT) { // Classe facture $result = $object->setPaid($user); - if ($result >= 0) - { + if ($result >= 0) { $db->commit(); } else { setEventMessages($object->error, $object->errors, 'errors'); @@ -938,11 +888,9 @@ if (empty($reshook)) } } } // Delete payment - elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercancreate) - { + elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercancreate) { $object->fetch($id); - if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0) - { + if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0) { $paiement = new Paiement($db); $result = $paiement->fetch(GETPOST('paiement_id')); if ($result > 0) { @@ -956,9 +904,10 @@ if (empty($reshook)) } /* * Insert new invoice in database */ - elseif ($action == 'add' && $usercancreate) - { - if ($socid > 0) $object->socid = GETPOST('socid', 'int'); + elseif ($action == 'add' && $usercancreate) { + if ($socid > 0) { + $object->socid = GETPOST('socid', 'int'); + } $selectedLines = GETPOST('toselect', 'array'); $db->begin(); @@ -970,8 +919,7 @@ if (empty($reshook)) if ($ret < 0) $error++; // Replacement invoice - if (GETPOST('type') == Facture::TYPE_REPLACEMENT) - { + if (GETPOST('type') == Facture::TYPE_REPLACEMENT) { $dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); if (empty($dateinvoice)) { $error++; @@ -1014,7 +962,7 @@ if (empty($reshook)) $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); // Proprietes particulieres a facture de remplacement - $object->fk_facture_source = $_POST['fac_replacement']; + $object->fk_facture_source = GETPOST('fac_replacement', 'int'); $object->type = Facture::TYPE_REPLACEMENT; $id = $object->createFromCurrent($user); @@ -1025,11 +973,9 @@ if (empty($reshook)) } // Credit note invoice - if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) - { + if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) { $sourceinvoice = GETPOST('fac_avoir', 'int'); - if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) - { + if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CorrectInvoice")), null, 'errors'); $action = 'create'; @@ -1077,10 +1023,8 @@ if (empty($reshook)) $object->type = Facture::TYPE_CREDIT_NOTE; $facture_source = new Facture($db); // fetch origin object - if ($facture_source->fetch($object->fk_facture_source) > 0) - { - if ($facture_source->type == Facture::TYPE_SITUATION) - { + if ($facture_source->fetch($object->fk_facture_source) > 0) { + if ($facture_source->type == Facture::TYPE_SITUATION) { $object->situation_counter = $facture_source->situation_counter; $object->situation_cycle_ref = $facture_source->situation_cycle_ref; $facture_source->fetchPreviousNextSituationInvoice(); @@ -1113,22 +1057,18 @@ if (empty($reshook)) } - if ($facture_source->type == Facture::TYPE_SITUATION) - { + if ($facture_source->type == Facture::TYPE_SITUATION) { $source_fk_prev_id = $line->fk_prev_id; // temporary storing situation invoice fk_prev_id $line->fk_prev_id = $line->id; // The new line of the new credit note we are creating must be linked to the situation invoice line it is created from - if (!empty($facture_source->tab_previous_situation_invoice)) - { + if (!empty($facture_source->tab_previous_situation_invoice)) { // search the last standard invoice in cycle and the possible credit note between this last and facture_source // TODO Move this out of loop of $facture_source->lines $tab_jumped_credit_notes = array(); $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1; $searchPreviousInvoice = true; - while ($searchPreviousInvoice) - { - if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type == Facture::TYPE_SITUATION || $lineIndex < 1) - { + while ($searchPreviousInvoice) { + if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type == Facture::TYPE_SITUATION || $lineIndex < 1) { $searchPreviousInvoice = false; // find, exit; break; } else { @@ -1140,10 +1080,8 @@ if (empty($reshook)) } $maxPrevSituationPercent = 0; - foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) - { - if ($prevLine->id == $source_fk_prev_id) - { + foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) { + if ($prevLine->id == $source_fk_prev_id) { $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent); //$line->subprice = $line->subprice - $prevLine->subprice; @@ -1168,10 +1106,8 @@ if (empty($reshook)) // If there is some credit note between last situation invoice and invoice used for credit note generation (note: credit notes are stored as delta) $maxPrevSituationPercent = 0; foreach ($tab_jumped_credit_notes as $index => $creditnoteid) { - foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) - { - if ($prevLine->fk_prev_id == $source_fk_prev_id) - { + foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) { + if ($prevLine->fk_prev_id == $source_fk_prev_id) { $maxPrevSituationPercent = $prevLine->situation_percent; $line->total_ht -= $prevLine->total_ht; @@ -1225,10 +1161,8 @@ if (empty($reshook)) } } - if (GETPOST('invoiceAvoirWithPaymentRestAmount', 'int') == 1 && $id > 0) - { - if ($facture_source->fetch($object->fk_facture_source) > 0) - { + if (GETPOST('invoiceAvoirWithPaymentRestAmount', 'int') == 1 && $id > 0) { + if ($facture_source->fetch($object->fk_facture_source) > 0) { $totalpaye = $facture_source->getSommePaiement(); $totalcreditnotes = $facture_source->getSumCreditNotesUsed(); $totaldeposits = $facture_source->getSumDepositsUsed(); @@ -1253,8 +1187,7 @@ if (empty($reshook)) } // Standard invoice or Deposit invoice, created from a Predefined template invoice - if ((GETPOST('type') == Facture::TYPE_STANDARD || GETPOST('type') == Facture::TYPE_DEPOSIT) && GETPOST('fac_rec', 'int') > 0) - { + if ((GETPOST('type') == Facture::TYPE_STANDARD || GETPOST('type') == Facture::TYPE_DEPOSIT) && GETPOST('fac_rec', 'int') > 0) { $dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); if (empty($dateinvoice)) { $error++; @@ -1268,8 +1201,7 @@ if (empty($reshook)) $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); - if (!$error) - { + if (!$error) { $object->socid = GETPOST('socid', 'int'); $object->type = GETPOST('type'); $object->ref = GETPOST('ref'); @@ -1299,8 +1231,7 @@ if (empty($reshook)) } // Standard or deposit invoice, not from a Predefined template invoice - if ((GETPOST('type') == Facture::TYPE_STANDARD || GETPOST('type') == Facture::TYPE_DEPOSIT || GETPOST('type') == Facture::TYPE_PROFORMA || (GETPOST('type') == Facture::TYPE_SITUATION && !GETPOST('situations'))) && GETPOST('fac_rec') <= 0) - { + if ((GETPOST('type') == Facture::TYPE_STANDARD || GETPOST('type') == Facture::TYPE_DEPOSIT || GETPOST('type') == Facture::TYPE_PROFORMA || (GETPOST('type') == Facture::TYPE_SITUATION && !GETPOST('situations'))) && GETPOST('fac_rec') <= 0) { $typeamount = GETPOST('typedeposit', 'aZ09'); $valuestandardinvoice = price2num(str_replace('%', '', GETPOST('valuestandardinvoice', 'alpha')), 'MU'); $valuedeposit = price2num(str_replace('%', '', GETPOST('valuedeposit', 'alpha')), 'MU'); @@ -1331,8 +1262,7 @@ if (empty($reshook)) $action = 'create'; } } elseif (GETPOST('type') == Facture::TYPE_DEPOSIT) { - if ($typeamount && !empty($origin) && !empty($originid)) - { + if ($typeamount && !empty($origin) && !empty($originid)) { if ($typeamount == 'amount' && $valuedeposit <= 0) { setEventMessages($langs->trans("ErrorAnAmountWithoutTaxIsRequired"), null, 'errors'); $error++; @@ -1351,8 +1281,7 @@ if (empty($reshook)) } } - if (!$error) - { + if (!$error) { // Si facture standard $object->socid = GETPOST('socid', 'int'); $object->type = GETPOST('type'); @@ -1398,8 +1327,7 @@ if (empty($reshook)) $object->fetch_thirdparty(); // If creation from another object of another module (Example: origin=propal, originid=1) - if (!empty($origin) && !empty($originid)) - { + if (!empty($origin) && !empty($originid)) { $regs = array(); // Parse element/subelement (ex: project_task) $element = $subelement = $origin; @@ -1445,15 +1373,13 @@ if (empty($reshook)) } } - if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) - { + if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) { $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); } $id = $object->create($user); // This include class to add_object_linked() and add add_contact() - if ($id > 0) - { + if ($id > 0) { dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); $classname = ucfirst($subelement); @@ -1463,45 +1389,45 @@ if (empty($reshook)) $result = $srcobject->fetch($object->origin_id); // If deposit invoice - down payment with 1 line (fixed amount or percent) - if (GETPOST('type') == Facture::TYPE_DEPOSIT && in_array($typeamount, array('amount', 'variable'))) - { + if (GETPOST('type') == Facture::TYPE_DEPOSIT && in_array($typeamount, array('amount', 'variable'))) { // Define the array $amountdeposit $amountdeposit = array(); - if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) - { - if ($typeamount == 'amount') $amount = $valuedeposit; - else $amount = $srcobject->total_ttc * ($valuedeposit / 100); + if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) { + if ($typeamount == 'amount') { + $amount = $valuedeposit; + } else { + $amount = $srcobject->total_ttc * ($valuedeposit / 100); + } $TTotalByTva = array(); - foreach ($srcobject->lines as &$line) - { + foreach ($srcobject->lines as &$line) { if (!empty($line->special_code)) continue; $TTotalByTva[$line->tva_tx] += $line->total_ttc; } - foreach ($TTotalByTva as $tva => &$total) - { + foreach ($TTotalByTva as $tva => &$total) { $coef = $total / $srcobject->total_ttc; // Calc coef $am = $amount * $coef; $amount_ttc_diff += $am; $amountdeposit[$tva] += $am / (1 + $tva / 100); // Convert into HT for the addline } } else { - if ($typeamount == 'amount') - { + if ($typeamount == 'amount') { $amountdeposit[0] = $valuedeposit; - } elseif ($typeamount == 'variable') - { - if ($result > 0) - { + } elseif ($typeamount == 'variable') { + if ($result > 0) { $totalamount = 0; $lines = $srcobject->lines; $numlines = count($lines); for ($i = 0; $i < $numlines; $i++) { $qualified = 1; - if (empty($lines[$i]->qty)) $qualified = 0; // We discard qty=0, it is an option - if (!empty($lines[$i]->special_code)) $qualified = 0; // We discard special_code (frais port, ecotaxe, option, ...) + if (empty($lines[$i]->qty)) { + $qualified = 0; // We discard qty=0, it is an option + } + if (!empty($lines[$i]->special_code)) { + $qualified = 0; // We discard special_code (frais port, ecotaxe, option, ...) + } if ($qualified) { $totalamount += $lines[$i]->total_ht; // Fixme : is it not for the customer ? Shouldn't we take total_ttc ? $tva_tx = $lines[$i]->tva_tx; @@ -1523,7 +1449,9 @@ if (empty($reshook)) foreach ($amountdeposit as $tva => $amount) { - if (empty($amount)) continue; + if (empty($amount)) { + continue; + } $arraylist = array( 'amount' => 'FixAmount', @@ -1568,8 +1496,7 @@ if (empty($reshook)) $diff = $object->total_ttc - $amount_ttc_diff; - if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) - { + if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) { $object->fetch_lines(); $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100); $object->updateline($object->lines[0]->id, $object->lines[0]->desc, $subprice_diff, $object->lines[0]->qty, $object->lines[0]->remise_percent, $object->lines[0]->date_start, $object->lines[0]->date_end, $object->lines[0]->tva_tx, 0, 0, 'HT', $object->lines[0]->info_bits, $object->lines[0]->product_type, 0, 0, 0, $object->lines[0]->pa_ht, $object->lines[0]->label, 0, array(), 100); @@ -1579,11 +1506,9 @@ if (empty($reshook)) // standard invoice, credit note, or down payment from a percent of all lines if (GETPOST('type') != Facture::TYPE_DEPOSIT || (GETPOST('type') == Facture::TYPE_DEPOSIT && $typeamount == 'variablealllines')) { - if ($result > 0) - { + if ($result > 0) { $lines = $srcobject->lines; - if (empty($lines) && method_exists($srcobject, 'fetch_lines')) - { + if (empty($lines) && method_exists($srcobject, 'fetch_lines')) { $srcobject->fetch_lines(); $lines = $srcobject->lines; } @@ -1610,15 +1535,22 @@ if (empty($reshook)) $fk_parent_line = 0; $num = count($lines); - for ($i = 0; $i < $num; $i++) - { - if (!in_array($lines[$i]->id, $selectedLines)) continue; // Skip unselected lines + for ($i = 0; $i < $num; $i++) { + if (!in_array($lines[$i]->id, $selectedLines)) { + continue; // Skip unselected lines + } // Don't add lines with qty 0 when coming from a shipment including all order lines - if ($srcobject->element == 'shipping' && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS && $lines[$i]->qty == 0) continue; + if ($srcobject->element == 'shipping' && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS && $lines[$i]->qty == 0) { + continue; + } // Don't add closed lines when coming from a contract (Set constant to '0,5' to exclude also inactive lines) - if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE = '5'; - if ($srcobject->element == 'contrat' && in_array($lines[$i]->statut, explode(',', $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE))) continue; + if (!isset($conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE)) { + $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE = '5'; + } + if ($srcobject->element == 'contrat' && in_array($lines[$i]->statut, explode(',', $conf->global->CONTRACT_EXCLUDE_SERVICES_STATUS_FOR_INVOICE))) { + continue; + } $label = (!empty($lines[$i]->label) ? $lines[$i]->label : ''); $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle); @@ -1649,23 +1581,29 @@ if (empty($reshook)) // Date start $date_start = false; - if ($lines[$i]->date_debut_prevue) + if ($lines[$i]->date_debut_prevue) { $date_start = $lines[$i]->date_debut_prevue; - if ($lines[$i]->date_debut_reel) + } + if ($lines[$i]->date_debut_reel) { $date_start = $lines[$i]->date_debut_reel; - if ($lines[$i]->date_start) + } + if ($lines[$i]->date_start) { $date_start = $lines[$i]->date_start; + } - // Date end + // Date end $date_end = false; - if ($lines[$i]->date_fin_prevue) + if ($lines[$i]->date_fin_prevue) { $date_end = $lines[$i]->date_fin_prevue; - if ($lines[$i]->date_fin_reel) + } + if ($lines[$i]->date_fin_reel) { $date_end = $lines[$i]->date_fin_reel; - if ($lines[$i]->date_end) + } + if ($lines[$i]->date_end) { $date_end = $lines[$i]->date_end; + } - // Reset fk_parent_line for no child products and special product + // Reset fk_parent_line for no child products and special product if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) { $fk_parent_line = 0; } @@ -1768,8 +1706,7 @@ if (empty($reshook)) } // Situation invoices - if (GETPOST('type') == Facture::TYPE_SITUATION && GETPOST('situations')) - { + if (GETPOST('type') == Facture::TYPE_SITUATION && GETPOST('situations')) { $dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); if (empty($dateinvoice)) { $error++; @@ -2708,8 +2645,9 @@ if (empty($reshook)) } } - if ($error) + if ($error) { $action = 'edit_extras'; + } } if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) { @@ -2753,8 +2691,9 @@ if (empty($reshook)) } } - if ($error) + if ($error) { $action = 'edit_extras'; + } } } @@ -2776,6 +2715,7 @@ $now = dol_now(); $title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('Card'); $helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes"; + llxHeader('', $title, $helpurl); // Mode creation @@ -2787,15 +2727,15 @@ if ($action == 'create') print load_fiche_titre($langs->trans('NewBill'), '', 'bill'); - if ($socid > 0) + if ($socid > 0) { $res = $soc->fetch($socid); + } $currency_code = $conf->currency; // Load objectsrc $remise_absolue = 0; - if (!empty($origin) && !empty($originid)) - { + if (!empty($origin) && !empty($originid)) { // Parse element/subelement (ex: project_task) $element = $subelement = $origin; $regs = array(); @@ -2847,11 +2787,11 @@ if ($action == 'create') $projectid = (!empty($projectid) ? $projectid : $objectsrc->fk_project); $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : (!empty($objectsrc->ref_customer) ? $objectsrc->ref_customer : '')); - $ref_int = (!empty($objectsrc->ref_int) ? $objectsrc->ref_int : ''); // only if socid not filled else it's allready done upper - if (empty($socid)) + if (empty($socid)) { $soc = $objectsrc->thirdparty; + } $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $dateinvoice); @@ -2925,8 +2865,7 @@ if ($action == 'create') print ajax_combobox('situations'); } - if ($origin == 'contrat') - { + if ($origin == 'contrat') { $langs->load("admin"); $text = $langs->trans("ToCreateARecurringInvoice"); $text .= ' '.$langs->trans("ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv("MenuFinancial"), $langs->transnoentitiesnoconv("BillsCustomers"), $langs->transnoentitiesnoconv("ListOfTemplates")); @@ -2960,14 +2899,12 @@ if ($action == 'create') $exampletemplateinvoice = new FactureRec($db); $invoice_predefined = new FactureRec($db); - if (empty($origin) && empty($originid) && GETPOST('fac_rec', 'int') > 0) - { + if (empty($origin) && empty($originid) && GETPOST('fac_rec', 'int') > 0) { $invoice_predefined->fetch(GETPOST('fac_rec', 'int')); } // Thirdparty - if ($soc->id > 0 && (!GETPOST('fac_rec', 'int') || !empty($invoice_predefined->frequency))) - { + if ($soc->id > 0 && (!GETPOST('fac_rec', 'int') || !empty($invoice_predefined->frequency))) { // If thirdparty known and not a predefined invoiced without a recurring rule print ''.$langs->trans('Customer').''; print ''; @@ -2990,8 +2927,7 @@ if ($action == 'create') print ''; print img_picto('', 'company').$form->select_company($soc->id, 'socid', '((s.client = 1 OR s.client = 3) AND s.status=1)', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); // Option to reload page to retrieve customer informations. - if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) - { + if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) { print ''; $text = ''; $text .= ' '; $text = ' '; @@ -3286,24 +3214,19 @@ if ($action == 'create') } - if (empty($origin)) - { - if ($socid > 0) - { + if (empty($origin)) { + if ($socid > 0) { // Credit note - if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) - { + if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) { // Show link for credit note $facids = $facturestatic->list_qualified_avoir_invoices($soc->id); - if ($facids < 0) - { + if ($facids < 0) { dol_print_error($db, $facturestatic); exit; } $optionsav = ""; $newinvoice_static = new Facture($db); - foreach ($facids as $key => $valarray) - { + foreach ($facids as $key => $valarray) { $newinvoice_static->id = $key; $newinvoice_static->ref = $valarray ['ref']; $newinvoice_static->statut = $valarray ['status']; @@ -3321,7 +3244,9 @@ if ($action == 'create') print '
'; $tmp = 'global->INVOICE_CREDIT_NOTE_STANDALONE)) || $invoice_predefined->id > 0) $tmp .= ' disabled'; + if ((!$optionsav && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) || $invoice_predefined->id > 0) { + $tmp .= ' disabled'; + } $tmp .= '> '; // Show credit note options only if we checked credit note print '