diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 32cebbe8284..447c2b4385e 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -73,7 +73,7 @@ $search_montant_ht = GETPOST('search_montant_ht', 'alpha'); $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha'); $origin = GETPOST('origin', 'alpha'); $originid = (GETPOST('originid', 'int') ? GETPOST('originid', 'int') : GETPOST('origin_id', 'int')); // For backward compatibility - + // PDF $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); @@ -111,7 +111,7 @@ $parameters = array('socid' => $socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not includ_once - + // Action clone object if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->facture->creer) { if (1 == 0 && empty($_REQUEST ["clone_content"]) && empty($_REQUEST ["clone_receivers"])) { @@ -128,7 +128,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->facture->c } } } -} +} // Change status of invoice else if ($action == 'reopen' && $user->rights->facture->creer) { @@ -142,22 +142,22 @@ else if ($action == 'reopen' && $user->rights->facture->creer) { $mesgs [] = '
' . $object->error . '
'; } } -} +} // Delete invoice else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->supprimer) { $result = $object->fetch($id); $object->fetch_thirdparty(); - + $idwarehouse = GETPOST('idwarehouse'); - + $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); } else { $qualified_for_stock_change = $object->hasProductsOrServices(1); } - + $result = $object->delete(0, 0, $idwarehouse); if ($result > 0) { header('Location: ' . DOL_URL_ROOT . '/compta/facture/list.php'); @@ -165,13 +165,13 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fact } else { $mesgs [] = '
' . $object->error . '
'; } -} +} // Delete line else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer) { $object->fetch($id); $object->fetch_thirdparty(); - + $result = $object->deleteline($_GET ['lineid'], $user); if ($result > 0) { // Define output language @@ -197,19 +197,19 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights-> $mesgs [] = '
' . $object->error . '
'; $action = ''; } -} +} // Delete link of credit note to invoice else if ($action == 'unlinkdiscount' && $user->rights->facture->creer) { $discount = new DiscountAbsolute($db); $result = $discount->fetch($_GET ["discountid"]); $discount->unlink_invoice(); -} +} // Validation else if ($action == 'valid' && $user->rights->facture->creer) { $object->fetch($id); - + // On verifie signe facture if ($object->type == Facture::TYPE_CREDIT_NOTE) { // Si avoir, le signe doit etre negatif @@ -224,20 +224,20 @@ else if ($action == 'valid' && $user->rights->facture->creer) { $action = ''; } } -} +} else if ($action == 'set_thirdparty' && $user->rights->facture->creer) { $object->fetch($id); $object->setValueFrom('fk_soc', $socid); - + header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $id); exit(); -} +} else if ($action == 'classin' && $user->rights->facture->creer) { $object->fetch($id); $object->setProject($_POST ['projectid']); -} +} else if ($action == 'setmode' && $user->rights->facture->creer) { $object->fetch($id); @@ -263,7 +263,7 @@ else if ($action == 'setmode' && $user->rights->facture->creer) { $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); if ($result < 0) dol_print_error($db, $object->error); - + $old_date_lim_reglement = $object->date_lim_reglement; $new_date_lim_reglement = $object->calculate_date_lim_reglement(); if ($new_date_lim_reglement > $old_date_lim_reglement) @@ -310,49 +310,49 @@ else if ($action == 'setmode' && $user->rights->facture->creer) { require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php'; $discount = new DiscountAbsolute($db); $discount->fetch($_POST ["remise_id_for_payment"]); - + $result = $discount->link_to_invoice(0, $id); if ($result < 0) { $mesgs [] = '
' . $discount->error . '
'; } } -} +} else if ($action == 'set_ref_client' && $user->rights->facture->creer) { $object->fetch($id); $object->set_ref_client($_POST ['ref_client']); -} +} // Classify to validated else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->valider) { $idwarehouse = GETPOST('idwarehouse'); - + $object->fetch($id); $object->fetch_thirdparty(); - + // Check parameters - + // Check for mandatory prof id for($i = 1; $i < 5; $i ++) { - + $idprof_mandatory = 'SOCIETE_IDPROF' . ($i) . '_INVOICE_MANDATORY'; $idprof = 'idprof' . $i; if (! $object->thirdparty->$idprof && ! empty($conf->global->$idprof_mandatory)) { if (! $error) $langs->load("errors"); $error ++; - + setEventMessage($langs->trans('ErrorProdIdIsMandatory', $langs->transcountry('ProfId' . $i, $object->thirdparty->country_code)), 'errors'); } } - + $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); } else { $qualified_for_stock_change = $object->hasProductsOrServices(1); } - + // Check for warehouse if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) { if (! $idwarehouse || $idwarehouse == - 1) { @@ -361,7 +361,7 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->factu $action = ''; } } - + if (! $error) { $result = $object->validate($user, '', $idwarehouse); if ($result >= 0) { @@ -384,22 +384,22 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->factu setEventMessage($object->error, 'errors'); } } -} +} // Go back to draft status (unvalidate) else if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->valider) || $user->rights->facture->invoice_advance->unvalidate)) { $idwarehouse = GETPOST('idwarehouse'); - + $object->fetch($id); $object->fetch_thirdparty(); - + $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); } else { $qualified_for_stock_change = $object->hasProductsOrServices(1); } - + // Check parameters if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) { if (! $idwarehouse || $idwarehouse == - 1) { @@ -408,18 +408,18 @@ else if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_ $action = ''; } } - + if (! $error) { // On verifie si la facture a des paiements $sql = 'SELECT pf.amount'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf'; $sql .= ' WHERE pf.fk_facture = ' . $object->id; - + $result = $db->query($sql); if ($result) { $i = 0; $num = $db->num_rows($result); - + while ($i < $num) { $objp = $db->fetch_object($result); $totalpaye += $objp->amount; @@ -428,16 +428,16 @@ else if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_ } else { dol_print_error($db, ''); } - + $resteapayer = $object->total_ttc - $totalpaye; - + // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees $ventilExportCompta = $object->getVentilExportCompta(); - + // On verifie si aucun paiement n'a ete effectue if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0) { $object->set_draft($user, $idwarehouse); - + // Define output language $outputlangs = $langs; $newlang = ''; @@ -455,7 +455,7 @@ else if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_ } } } -} +} // Classify "paid" else if ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->facture->paiement) { @@ -481,16 +481,16 @@ else if ($action == 'confirm_canceled' && $confirm == 'yes') { } else { setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), 'errors'); } -} +} // Convertir en reduc else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->facture->creer) { $db->begin(); - + $object->fetch($id); $object->fetch_thirdparty(); $object->fetch_lines(); - + if (! $object->paye) // protection against multiple submit { // Boucle sur chaque taux de tva @@ -501,7 +501,7 @@ else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->righ $amount_ttc [$line->tva_tx] += $line->total_ttc; $i ++; } - + // Insert one discount by VAT rate category $discount = new DiscountAbsolute($db); if ($object->type == Facture::TYPE_CREDIT_NOTE) @@ -515,21 +515,21 @@ else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->righ $discount->tva_tx = abs($object->total_ttc); $discount->fk_soc = $object->socid; $discount->fk_facture_source = $object->id; - + $error = 0; 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]); $discount->tva_tx = abs($tva_tx); - + $result = $discount->create($user); if ($result < 0) { $error ++; break; } } - + if (! $error) { // Classe facture $result = $object->set_paid($user); @@ -545,7 +545,7 @@ else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->righ $db->rollback(); } } -} +} /* * Insert new invoice in database @@ -553,17 +553,17 @@ else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->righ else if ($action == 'add' && $user->rights->facture->creer) { if ($socid > 0) $object->socid = GETPOST('socid', 'int'); - + $db->begin(); - + $error = 0; - + // Fill array 'array_options' with data from add form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object); if ($ret < 0) $error ++; - + // Replacement invoice if ($_POST ['type'] == 1) { $datefacture = dol_mktime(12, 0, 0, $_POST ['remonth'], $_POST ['reday'], $_POST ['reyear']); @@ -571,17 +571,17 @@ else if ($action == 'add' && $user->rights->facture->creer) { $error ++; setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors'); } - + if (! ($_POST ['fac_replacement'] > 0)) { $error ++; setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ReplaceInvoice")), 'errors'); } - + if (! $error) { // This is a replacement invoice $result = $object->fetch($_POST ['fac_replacement']); $object->fetch_thirdparty(); - + $object->date = $datefacture; $object->note_public = trim($_POST ['note_public']); $object->note = trim($_POST ['note']); @@ -593,36 +593,36 @@ else if ($action == 'add' && $user->rights->facture->creer) { $object->mode_reglement_id = $_POST ['mode_reglement_id']; $object->remise_absolue = $_POST ['remise_absolue']; $object->remise_percent = $_POST ['remise_percent']; - + // Proprietes particulieres a facture de remplacement $object->fk_facture_source = $_POST ['fac_replacement']; $object->type = Facture::TYPE_REPLACEMENT; - + $id = $object->createFromCurrent($user); if ($id <= 0) $mesgs [] = $object->error; } } - + // Credit note invoice if ($_POST ['type'] == 2) { if (! $_POST ['fac_avoir'] > 0) { $error ++; setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CorrectInvoice")), 'errors'); } - + $datefacture = dol_mktime(12, 0, 0, $_POST ['remonth'], $_POST ['reday'], $_POST ['reyear']); if (empty($datefacture)) { $error ++; setEventMessage($langs->trans("ErrorFieldRequired", $langs->trans("Date")), 'errors'); } - + if (! $error) { // Si facture avoir $datefacture = dol_mktime(12, 0, 0, $_POST ['remonth'], $_POST ['reday'], $_POST ['reyear']); - + // $result=$object->fetch($_POST['fac_avoir']); - + $object->socid = GETPOST('socid', 'int'); $object->number = $_POST ['facnumber']; $object->date = $datefacture; @@ -636,13 +636,13 @@ else if ($action == 'add' && $user->rights->facture->creer) { $object->mode_reglement_id = $_POST ['mode_reglement_id']; $object->remise_absolue = $_POST ['remise_absolue']; $object->remise_percent = $_POST ['remise_percent']; - + // Proprietes particulieres a facture avoir $object->fk_facture_source = $_POST ['fac_avoir']; $object->type = Facture::TYPE_CREDIT_NOTE; - + $id = $object->create($user); - + // Add predefined lines for($i = 1; $i <= $NBLINES; $i ++) { if ($_POST ['idprod' . $i]) { @@ -655,7 +655,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { } } } - + // Standard invoice or Deposit invoice created from a Predefined invoice if (($_POST ['type'] == 0 || $_POST ['type'] == 3) && $_POST ['fac_rec'] > 0) { $datefacture = dol_mktime(12, 0, 0, $_POST ['remonth'], $_POST ['reday'], $_POST ['reyear']); @@ -663,7 +663,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { $error ++; setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors'); } - + if (! $error) { $object->socid = GETPOST('socid', 'int'); $object->type = $_POST ['type']; @@ -674,27 +674,27 @@ else if ($action == 'add' && $user->rights->facture->creer) { $object->ref_client = $_POST ['ref_client']; $object->ref_int = $_POST ['ref_int']; $object->modelpdf = $_POST ['model']; - + // Source facture $object->fac_rec = $_POST ['fac_rec']; - + $id = $object->create($user); } } - + // Standard or deposit or proforma invoice if (($_POST ['type'] == 0 || $_POST ['type'] == 3 || $_POST ['type'] == 4) && $_POST ['fac_rec'] <= 0) { if (GETPOST('socid', 'int') < 1) { $error ++; setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), 'errors'); } - + $datefacture = dol_mktime(12, 0, 0, $_POST ['remonth'], $_POST ['reday'], $_POST ['reyear']); if (empty($datefacture)) { $error ++; setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors'); } - + if (! $error) { // Si facture standard $object->socid = GETPOST('socid', 'int'); @@ -713,7 +713,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { $object->remise_absolue = $_POST ['remise_absolue']; $object->remise_percent = $_POST ['remise_percent']; $object->fetch_thirdparty(); - + // If creation from another object of another module (Example: origin=propal, originid=1) if ($_POST ['origin'] && $_POST ['originid']) { // Parse element/subelement (ex: project_task) @@ -722,7 +722,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { $element = $regs [1]; $subelement = $regs [2]; } - + // For compatibility if ($element == 'order') { $element = $subelement = 'commande'; @@ -740,34 +740,34 @@ else if ($action == 'add' && $user->rights->facture->creer) { if ($element == 'shipping') { $element = $subelement = 'expedition'; } - + $object->origin = $_POST ['origin']; $object->origin_id = $_POST ['originid']; - + // Possibility to add external linked objects with hooks $object->linked_objects [$object->origin] = $object->origin_id; 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); - + if ($id > 0) { // If deposit invoice if ($_POST ['type'] == 3) { $typeamount = GETPOST('typedeposit', 'alpha'); $valuedeposit = GETPOST('valuedeposit', 'int'); - + if ($typeamount == 'amount') { $amountdeposit = $valuedeposit; } else { $amountdeposit = 0; - + dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); - + $classname = ucfirst($subelement); $srcobject = new $classname($db); - + dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add deposit lines"); $result = $srcobject->fetch($object->origin_id); if ($result > 0) { @@ -777,7 +777,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { for($i = 0; $i < $numlines; $i ++) { $totalamount += $lines [$i]->total_ht; } - + if ($totalamount != 0) { $amountdeposit = ($totalamount * $valuedeposit) / 100; } @@ -786,9 +786,9 @@ else if ($action == 'add' && $user->rights->facture->creer) { $error ++; } } - + $result = $object->addline( - $langs->trans('Deposit'), + $langs->trans('Deposit'), $amountdeposit, // subprice 1, // quantity $lines [$i]->tva_tx, 0, // localtax1_tx @@ -799,39 +799,39 @@ else if ($action == 'add' && $user->rights->facture->creer) { 0, // date_end 0, $lines [$i]->info_bits, // info_bits 0, // info_bits - 'HT', - 0, + 'HT', + 0, 0, // product_type - 1, - $lines [$i]->special_code, - $object->origin, - 0, - 0, - 0, - 0, + 1, + $lines [$i]->special_code, + $object->origin, + 0, + 0, + 0, + 0, $langs->trans('Deposit') ); } else { - + dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); - + $classname = ucfirst($subelement); $srcobject = new $classname($db); - + dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines"); $result = $srcobject->fetch($object->origin_id); if ($result > 0) { $lines = $srcobject->lines; if (empty($lines) && method_exists($srcobject, 'fetch_lines')) $lines = $srcobject->fetch_lines(); - + $fk_parent_line = 0; $num = count($lines); - + for($i = 0; $i < $num; $i ++) { $label = (! empty($lines [$i]->label) ? $lines [$i]->label : ''); $desc = (! empty($lines [$i]->desc) ? $lines [$i]->desc : $lines [$i]->libelle); - + if ($lines [$i]->subprice < 0) { // Negative line, we create a discount line $discount = new DiscountAbsolute($db); @@ -853,7 +853,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { } else { // Positive line $product_type = ($lines [$i]->product_type ? $lines [$i]->product_type : 0); - + // Date start $date_start = false; if ($lines [$i]->date_debut_prevue) @@ -862,7 +862,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { $date_start = $lines [$i]->date_debut_reel; if ($lines [$i]->date_start) $date_start = $lines [$i]->date_start; - + // Date end $date_end = false; if ($lines [$i]->date_fin_prevue) @@ -871,20 +871,20 @@ else if ($action == 'add' && $user->rights->facture->creer) { $date_end = $lines [$i]->date_fin_reel; if ($lines [$i]->date_end) $date_end = $lines [$i]->date_end; - + // 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; } - + // Extrafields if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines [$i], 'fetch_optionals')) { $lines [$i]->fetch_optionals($lines [$i]->rowid); $array_option = $lines [$i]->array_options; } - + $result = $object->addline($desc, $lines [$i]->subprice, $lines [$i]->qty, $lines [$i]->tva_tx, $lines [$i]->localtax1_tx, $lines [$i]->localtax2_tx, $lines [$i]->fk_product, $lines [$i]->remise_percent, $date_start, $date_end, 0, $lines [$i]->info_bits, $lines [$i]->fk_remise_except, 'HT', 0, $product_type, $lines [$i]->rang, $lines [$i]->special_code, $object->origin, $lines [$i]->rowid, $fk_parent_line, $lines [$i]->fk_fournprice, $lines [$i]->pa_ht, $label, $array_option); - + if ($result > 0) { $lineid = $result; } else { @@ -892,14 +892,14 @@ else if ($action == 'add' && $user->rights->facture->creer) { $error ++; break; } - + // Defined the new fk_parent_line if ($result > 0 && $lines [$i]->product_type == 9) { $fk_parent_line = $result; } } } - + // Hooks $parameters = array('objFrom' => $srcobject); $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been @@ -918,7 +918,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { } // If some invoice's lines already known else { $id = $object->create($user); - + for($i = 1; $i <= $NBLINES; $i ++) { if ($_POST ['idprod' . $i]) { $product = new Product($db); @@ -931,7 +931,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { } } } - + // End of object creation, we show it if ($id > 0 && ! $error) { $db->commit(); @@ -944,13 +944,13 @@ else if ($action == 'add' && $user->rights->facture->creer) { $_GET ["originid"] = $_POST ["originid"]; $mesgs [] = '
' . $object->error . '
'; } -} +} // Add a new line else if (($action == 'addline' || $action == 'addline_predef') && $user->rights->facture->creer) { $langs->load('errors'); $error = 0; - + // Set if we used free entry or predefined product if (GETPOST('addline_libre')) { $predef = ''; @@ -974,7 +974,7 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- } $qty = GETPOST('qty' . $predef); $remise_percent = GETPOST('remise_percent' . $predef); - + // Extrafields $extrafieldsline = new ExtraFields($db); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); @@ -986,7 +986,7 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- unset($_POST ["options_" . $key . $predef]); } } - + if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && ($qty < 0)) { setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors'); $error ++; @@ -1008,7 +1008,7 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors'); $error ++; } - + if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod))) { $ret = $object->fetch($id); if ($ret < 0) { @@ -1016,16 +1016,16 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- exit(); } $ret = $object->fetch_thirdparty(); - + // Clean parameters $date_start = dol_mktime(GETPOST('date_start' . $predef . 'hour'), GETPOST('date_start' . $predef . 'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year')); $date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year')); $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT'); - + // Define special_code for special lines $special_code = 0; // if (empty($_POST['qty'])) $special_code=3; // Options should not exists on invoices - + // Ecrase $pu par celui du produit // Ecrase $desc par celui du produit // Ecrase $txtva par celui du produit @@ -1033,9 +1033,9 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- if (! empty($idprod)) { $prod = new Product($db); $prod->fetch($idprod); - + $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : ''); - + // Update if prices fields are defined if (GETPOST('usenewaddlineform')) { $pu_ht = price2num($price_ht, 'MU'); @@ -1046,7 +1046,7 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- } else { $tva_tx = get_default_tva($mysoc, $object->client, $prod->id); $tva_npr = get_default_npr($mysoc, $object->client, $prod->id); - + // We define price for product if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level)) { $pu_ht = $prod->multiprices [$object->client->price_level]; @@ -1055,11 +1055,11 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- $price_base_type = $prod->multiprices_base_type [$object->client->price_level]; } elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; - + $prodcustprice = new Productcustomerprice($db); - + $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->client->id); - + $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); if ($result) { if (count($prodcustprice->lines) > 0) { @@ -1076,12 +1076,12 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- $price_min = $prod->price_min; $price_base_type = $prod->price_base_type; } - + // if price ht is forced (ie: calculated by margin rate and cost price) if (! empty($price_ht)) { $pu_ht = price2num($price_ht, 'MU'); $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU'); - } + } // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). @@ -1092,9 +1092,9 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU'); } } - + $desc = ''; - + // Define output language if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $outputlangs = $langs; @@ -1107,14 +1107,14 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } - + $desc = (! empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description; } else { $desc = $prod->description; } - + $desc = dol_concatdesc($desc, $product_desc); - + // Add custom code and origin country into description if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) { $tmptxt = '('; @@ -1128,7 +1128,7 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- $desc = dol_concatdesc($desc, $tmptxt); } } - + $type = $prod->type; } else { $pu_ht = price2num($price_ht, 'MU'); @@ -1139,26 +1139,26 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- $desc = $product_desc; $type = GETPOST('type'); } - + // Margin $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : ''); $buyingprice = price2num(GETPOST('buying_price' . $predef) ? GETPOST('buying_price' . $predef) : ''); - + // Local Taxes $localtax1_tx = get_localtax($tva_tx, 1, $object->client); $localtax2_tx = get_localtax($tva_tx, 2, $object->client); - + $info_bits = 0; if ($tva_npr) $info_bits |= 0x01; - + if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min))) { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); setEventMessage($mesg, 'errors'); } else { // Insert line $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $date_start, $date_end, 0, $info_bits, '', $price_base_type, $pu_ttc, $type, - 1, $special_code, '', 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_option); - + if ($result > 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { // Define output language @@ -1170,11 +1170,11 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } - + $ret = $object->fetch($id); // Reload to get new records facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } - + unset($_POST ['qty']); unset($_POST ['type']); unset($_POST ['remise_percent']); @@ -1189,7 +1189,7 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- unset($_POST ['np_marginRate']); unset($_POST ['np_markRate']); unset($_POST ['dp_desc']); - + unset($_POST ['idprod']); unset($_POST ['qty_predef']); unset($_POST ['remise_percent_predef']); @@ -1201,17 +1201,17 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights- } else { setEventMessage($object->error, 'errors'); } - + $action = ''; } } -} +} elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('cancel')) { if (! $object->fetch($id) > 0) dol_print_error($db); $object->fetch_thirdparty(); - + // Clean parameters $date_start = ''; $date_end = ''; @@ -1220,21 +1220,21 @@ elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST(' $description = dol_htmlcleanlastbr(GETPOST('product_desc')); $pu_ht = GETPOST('price_ht'); $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); - + // Define info_bits $info_bits = 0; if (preg_match('/\*/', $vat_rate)) $info_bits |= 0x01; - + // Define vat_rate $vat_rate = str_replace('*', '', $vat_rate); $localtax1_rate = get_localtax($vat_rate, 1, $object->client); $localtax2_rate = get_localtax($vat_rate, 2, $object->client); - + // Add buying price $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : ''); $buyingprice = price2num(GETPOST('buying_price') ? GETPOST('buying_price') : ''); - + // Extrafields $extrafieldsline = new ExtraFields($db); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); @@ -1246,21 +1246,21 @@ elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST(' unset($_POST ["options_" . $key]); } } - + // Check minimum price $productid = GETPOST('productid', 'int'); if (! empty($productid)) { $product = new Product($db); $product->fetch($productid); - + $type = $product->type; - + $price_min = $product->price_min; if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level)) $price_min = $product->multiprices_min [$object->client->price_level]; - + $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : ''); - + // Check price is not lower than minimum (check is done only for standard or replacement invoices) if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) { setEventMessage($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), 'errors'); @@ -1269,18 +1269,18 @@ elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST(' } else { $type = GETPOST('type'); $label = (GETPOST('product_label') ? GETPOST('product_label') : ''); - + // Check parameters if (GETPOST('type') < 0) { setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), 'errors'); $error ++; } } - + // Update line if (! $error) { $result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $date_start, $date_end, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, 0, $array_option); - + if ($result >= 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { // Define output language @@ -1294,11 +1294,11 @@ elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST(' $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } - + $ret = $object->fetch($id); // Reload to get new records facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } - + unset($_POST ['qty']); unset($_POST ['type']); unset($_POST ['productid']); @@ -1315,19 +1315,19 @@ elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST(' setEventMessage($object->error, 'errors'); } } -} +} else if ($action == 'updateligne' && $user->rights->facture->creer && $_POST ['cancel'] == $langs->trans('Cancel')) { header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $id); // Pour reaffichage de la fiche en cours d'edition exit(); -} +} // Modify line position (up) else if ($action == 'up' && $user->rights->facture->creer) { $object->fetch($id); $object->fetch_thirdparty(); $object->line_up($_GET ['rowid']); - + // Define output language $outputlangs = $langs; $newlang = ''; @@ -1341,7 +1341,7 @@ else if ($action == 'up' && $user->rights->facture->creer) { } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - + header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $object->id . '#' . $_GET ['rowid']); exit(); } // Modify line position (down) @@ -1349,7 +1349,7 @@ else if ($action == 'down' && $user->rights->facture->creer) { $object->fetch($id); $object->fetch_thirdparty(); $object->line_down($_GET ['rowid']); - + // Define output language $outputlangs = $langs; $newlang = ''; @@ -1363,7 +1363,7 @@ else if ($action == 'down' && $user->rights->facture->creer) { } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - + header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $object->id . '#' . $_GET ['rowid']); exit(); } @@ -1380,11 +1380,11 @@ if (GETPOST('linkedOrder')) { */ if (GETPOST('addfile')) { require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - + // Set tmp user directory $vardir = $conf->user->dir_output . "/" . $user->id; $upload_dir_tmp = $vardir . '/temp'; - + dol_add_file_process($upload_dir_tmp, 0, 0); $action = 'presend'; } @@ -1394,11 +1394,11 @@ if (GETPOST('addfile')) { */ if (! empty($_POST ['removedfile'])) { require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - + // Set tmp user directory $vardir = $conf->user->dir_output . "/" . $user->id; $upload_dir_tmp = $vardir . '/temp'; - + // TODO Delete only files that was uploaded from email form dol_remove_file_process($_POST ['removedfile'], 0); $action = 'presend'; @@ -1409,19 +1409,19 @@ if (! empty($_POST ['removedfile'])) { */ if (($action == 'send' || $action == 'relance') && ! $_POST ['addfile'] && ! $_POST ['removedfile'] && ! $_POST ['cancel']) { $langs->load('mails'); - + $actiontypecode = ''; $subject = ''; $actionmsg = ''; $actionmsg2 = ''; - + $result = $object->fetch($id); $result = $object->fetch_thirdparty(); - + if ($result > 0) { // $ref = dol_sanitizeFileName($object->ref); // $file = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - + // if (is_readable($file)) // { if ($_POST ['sendto']) { @@ -1440,16 +1440,16 @@ if (($action == 'send' || $action == 'relance') && ! $_POST ['addfile'] && ! $_P $sendtoid = $_POST ['receiver']; } } - + if (dol_strlen($sendto)) { $langs->load("commercial"); - + $from = $_POST ['fromname'] . ' <' . $_POST ['frommail'] . '>'; $replyto = $_POST ['replytoname'] . ' <' . $_POST ['replytomail'] . '>'; $message = $_POST ['message']; $sendtocc = $_POST ['sendtocc']; $deliveryreceipt = $_POST ['deliveryreceipt']; - + if ($action == 'send') { if (dol_strlen($_POST ['subject'])) $subject = $_POST ['subject']; @@ -1478,16 +1478,16 @@ if (($action == 'send' || $action == 'relance') && ! $_POST ['addfile'] && ! $_P } // $actionmsg2=$langs->transnoentities('Action'.$actiontypecode); } - + // Create form object include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; $formmail = new FormMail($db); - + $attachedfiles = $formmail->get_attached_files(); $filepath = $attachedfiles ['paths']; $filename = $attachedfiles ['names']; $mimetype = $attachedfiles ['mimes']; - + // Send mail require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php'; $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, - 1); @@ -1497,7 +1497,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST ['addfile'] && ! $_P $result = $mailfile->sendfile(); if ($result) { $error = 0; - + // Initialisation donnees $object->sendtoid = $sendtoid; $object->actiontypecode = $actiontypecode; @@ -1505,7 +1505,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST ['addfile'] && ! $_P $object->actionmsg2 = $actionmsg2; // Short text $object->fk_element = $object->id; $object->elementtype = $object->element; - + // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface = new Interfaces($db); @@ -1515,7 +1515,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST ['addfile'] && ! $_P $this->errors = $interface->errors; } // Fin appel triggers - + if ($error) { dol_print_error($db); } else { @@ -1556,9 +1556,9 @@ if (($action == 'send' || $action == 'relance') && ! $_POST ['addfile'] && ! $_P $mesgs [] = '
' . $langs->trans('ErrorFailedToReadEntity', $langs->trans("Invoice")) . '
'; dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.'); } - + $action = 'presend'; -} +} /* * Generate document @@ -1567,13 +1567,13 @@ else if ($action == 'builddoc') // En get ou en post { $object->fetch($id); $object->fetch_thirdparty(); - + // Save last template used to generate document if (GETPOST('model')) $object->setDocModel($user, GETPOST('model', 'alpha')); if (GETPOST('fk_bank')) $object->fk_bank = GETPOST('fk_bank'); - + // Define output language $outputlangs = $langs; $newlang = ''; @@ -1590,15 +1590,15 @@ else if ($action == 'builddoc') // En get ou en post dol_print_error($db, $result); exit(); } -} +} // Remove file in doc form else if ($action == 'remove_file') { if ($object->fetch($id)) { require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - + $object->fetch_thirdparty(); - + $langs->load("other"); $upload_dir = $conf->facture->dir_output; $file = $upload_dir . '/' . GETPOST('file'); @@ -1609,7 +1609,7 @@ else if ($action == 'remove_file') { setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); $action = ''; } -} +} // Print file else if ($action == 'print_file' and $user->rights->printipp->read) { @@ -1623,12 +1623,12 @@ else if ($action == 'print_file' and $user->rights->printipp->read) { if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture->creer) { if ($action == 'addcontact') { $result = $object->fetch($id); - + if ($result > 0 && $id > 0) { $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); $result = $object->add_contact($contactid, $_POST ["type"], $_POST ["source"]); } - + if ($result >= 0) { header("Location: " . $_SERVER ['PHP_SELF'] . "?id=" . $object->id); exit(); @@ -1640,7 +1640,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture- $mesgs [] = '
' . $object->error . '
'; } } - } + } // bascule du statut d'un contact else if ($action == 'swapstatut') { @@ -1649,13 +1649,13 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture- } else { dol_print_error($db); } - } + } // Efface un contact else if ($action == 'deletecontact') { $object->fetch($id); $result = $object->delete_contact($lineid); - + if ($result >= 0) { header("Location: " . $_SERVER ['PHP_SELF'] . "?id=" . $object->id); exit(); @@ -1671,7 +1671,7 @@ if ($action == 'update_extras') { $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); if ($ret < 0) $error ++; - + if (! $error) { // Actions on extra fields (by external module or standard code) // FIXME le hook fait double emploi avec le trigger !! @@ -1687,7 +1687,7 @@ if ($action == 'update_extras') { } else if ($reshook < 0) $error ++; } - + if ($error) $action = 'edit_extras'; } @@ -1721,16 +1721,17 @@ jQuery(document).ready(function() { * * ******************************************************************** */ -if ($action == 'create') { +if ($action == 'create') +{ $facturestatic = new Facture($db); $extralabels = $extrafields->fetch_name_optionals_label($facturestatic->table_element); - + print_fiche_titre($langs->trans('NewBill')); - + $soc = new Societe($db); if ($socid > 0) $res = $soc->fetch($socid); - + if (! empty($origin) && ! empty($originid)) { // Parse element/subelement (ex: project_task) $element = $subelement = $origin; @@ -1738,7 +1739,7 @@ if ($action == 'create') { $element = $regs [1]; $subelement = $regs [2]; } - + if ($element == 'project') { $projectid = $originid; } else { @@ -1756,27 +1757,27 @@ if ($action == 'create') { if ($element == 'shipping') { $element = $subelement = 'expedition'; } - + dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); - + $classname = ucfirst($subelement); $objectsrc = new $classname($db); $objectsrc->fetch($originid); if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) $objectsrc->fetch_lines(); $objectsrc->fetch_thirdparty(); - + $projectid = (! empty($objectsrc->fk_project) ? $objectsrc->fk_project : ''); $ref_client = (! empty($objectsrc->ref_client) ? $objectsrc->ref_client : ''); $ref_int = (! empty($objectsrc->ref_int) ? $objectsrc->ref_int : ''); - + $soc = $objectsrc->thirdparty; $cond_reglement_id = (! empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (! empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1)); $mode_reglement_id = (! empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (! empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0)); $remise_percent = (! empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (! empty($soc->remise_percent) ? $soc->remise_percent : 0)); $remise_absolue = (! empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (! empty($soc->remise_absolue) ? $soc->remise_absolue : 0)); $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? - 1 : 0; - + // Replicate extrafields $objectsrc->fetch_optionals($originid); $object->array_options = $objectsrc->array_options; @@ -1789,12 +1790,12 @@ if ($action == 'create') { $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? - 1 : 0; } $absolute_discount = $soc->getAvailableDiscounts(); - + if (! empty($conf->use_javascript_ajax)) { - print ajax_combobox('fac_replacement'); + //print ajax_combobox('fac_replacement'); print ajax_combobox('fac_avoir'); } - + print '
'; print ''; print ''; @@ -1805,12 +1806,12 @@ if ($action == 'create') { print ''; print ''; print ''; - + print ''; - + // Ref print ''; - + // Thirdparty print ''; if ($soc->id > 0) { @@ -1834,23 +1835,27 @@ if ($action == 'create') { print ''; } print '' . "\n"; - + // Predefined invoices - if (empty($origin) && empty($originid) && $socid > 0) { + if (empty($origin) && empty($originid) && $socid > 0) + { $sql = 'SELECT r.rowid, r.titre, r.total_ttc'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture_rec as r'; $sql .= ' WHERE r.fk_soc = ' . $soc->id; - + $resql = $db->query($sql); - if ($resql) { + if ($resql) + { $num = $db->num_rows($resql); $i = 0; - - if ($num > 0) { + + if ($num > 0) + { print ''; - + if ($socid > 0) { // Discounts for third party print ''; } - + // Date invoice print ''; - + // Payment term print ''; - + // Payment mode print ''; - + // Project if (! empty($conf->projet->enabled) && $socid > 0) { $formproject = new FormProjets($db); - + $langs->load('projects'); print ''; } - + // Other attributes $parameters = array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"'); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by @@ -2049,7 +2074,7 @@ if ($action == 'create') { if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields, 'edit'); } - + // Modele PDF print ''; print '"; - + // Public note print ''; print ''; @@ -2069,9 +2094,9 @@ if ($action == 'create') { } $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); print $doleditor->Create(1); - + // print ''; - + // Private note if (empty($user->societe_id)) { print ''; @@ -2086,7 +2111,7 @@ if ($action == 'create') { print $doleditor->Create(1); // print ''; } - + if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) { // TODO for compatibility if ($origin == 'contrat') { @@ -2095,7 +2120,7 @@ if ($action == 'create') { $objectsrc->remise_percent = $remise_percent; $objectsrc->update_price(1, - 1, 1); } - + print "\n"; print "\n"; print '' . "\n"; @@ -2103,7 +2128,7 @@ if ($action == 'create') { print '' . "\n"; print ''; print ''; - + $newclassname = $classname; if ($newclassname == 'Propal') $newclassname = 'CommercialProposal'; @@ -2111,7 +2136,7 @@ if ($action == 'create') { $newclassname = 'Order'; elseif ($newclassname == 'Expedition') $newclassname = 'Sending'; - + print ''; print ''; print '"; @@ -2119,7 +2144,7 @@ if ($action == 'create') { { print '"; } - + if ($mysoc->localtax2_assuj == "1") // Localtax2 IRPF { print '"; @@ -2129,7 +2154,7 @@ if ($action == 'create') { // Show deprecated optional form to add product line here if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) { print ''; } } - + print "
' . $langs->trans('Ref') . '' . $langs->trans('Draft') . '
' . $langs->trans('Customer') . '
' . $langs->trans('CreateFromRepeatableInvoice') . ''; print '
' . $langs->trans('Type') . ''; print '' . "\n"; - + // Standard invoice print '' . "\n"; - + // Proforma - if (! empty($conf->global->FACTURE_USE_PROFORMAT)) { + if (! empty($conf->global->FACTURE_USE_PROFORMAT)) + { print '' . "\n"; } - - if ((empty($origin)) || ((($origin == 'propal') || ($origin == 'commande')) && (! empty($originid)))) { + + if ((empty($origin)) || ((($origin == 'propal') || ($origin == 'commande')) && (! empty($originid)))) + { // Deposit print '' . "\n"; } - - if ($socid > 0) { + + if ($socid > 0) + { // Replacement print '' . "\n"; } - - if (empty($origin) && $socid > 0) { + + if (empty($origin) && $socid > 0) + { // Credit note print '' . "\n"; } - + print '
'; print ''; @@ -1915,9 +1922,10 @@ if ($action == 'create') { $desc = $form->textwithpicto($langs->trans("InvoiceStandardAsk"), $langs->transnoentities("InvoiceStandardDesc"), 1); print $desc; print '
'; print ''; print ''; @@ -1925,12 +1933,20 @@ if ($action == 'create') { print $desc; print '
'; - print ''; + print ''; print ''; + print ''; $desc = $form->textwithpicto($langs->trans("InvoiceDeposit"), $langs->transnoentities("InvoiceDepositDesc"), 1); print ''; if (($origin == 'propal') || ($origin == 'commande')) { @@ -1938,27 +1954,35 @@ if ($action == 'create') { $arraylist = array('amount' => 'FixAmount','variable' => 'VarAmount'); print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit'), 0, 0, 0, '', 1); print ''; - print '
' . $desc . '' . $langs->trans('Value') . ':'; + print '' . $langs->trans('Value') . ':'; } print '
'; print '
'; - print ''; print ''; + print ''; $text = $langs->trans("InvoiceReplacementAsk") . ' '; $text .= '
'; print '
'; print '
' . $langs->trans('Discounts') . ''; @@ -2016,32 +2041,32 @@ if ($action == 'create') { print '.'; print '
' . $langs->trans('Date') . ''; $form->select_date($dateinvoice, '', '', '', '', "add", 1, 1); print '
' . $langs->trans('PaymentConditionsShort') . ''; $form->select_conditions_paiements(isset($_POST ['cond_reglement_id']) ? $_POST ['cond_reglement_id'] : $cond_reglement_id, 'cond_reglement_id'); print '
' . $langs->trans('PaymentMode') . ''; $form->select_types_paiements(isset($_POST ['mode_reglement_id']) ? $_POST ['mode_reglement_id'] : $mode_reglement_id, 'mode_reglement_id'); print '
' . $langs->trans('Project') . ''; $formproject->select_projects($soc->id, $projectid, 'projectid'); print '
' . $langs->trans('Model') . ''; @@ -2057,7 +2082,7 @@ if ($action == 'create') { $liste = ModelePDFFactures::liste_modeles($db); print $form->selectarray('model', $liste, $conf->global->FACTURE_ADDON_PDF); print "
' . $langs->trans('NotePublic') . '
' . $langs->trans($newclassname) . '' . $objectsrc->getNomUrl(1) . '
' . $langs->trans('TotalHT') . '' . price($objectsrc->total_ht) . '
' . $langs->trans('TotalVAT') . '' . price($objectsrc->total_tva) . "
' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($objectsrc->total_localtax1) . "
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($objectsrc->total_localtax2) . "
'; - + // Zone de choix des produits predefinis a la creation print ''; print ''; @@ -2171,73 +2196,73 @@ if ($action == 'create') { } print "\n"; } - + print '
'; print '
\n"; - + // Button "Create Draft" print '
'; - + print "
\n"; - + // Show origin lines if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) { print '
'; - + $title = $langs->trans('ProductsAndServices'); print_titre($title); - + print ''; - + $objectsrc->printOriginLinesList(); - + print '
'; } - + print '
'; } else if ($id > 0 || ! empty($ref)) { /* * Show object in view mode */ - + $result = $object->fetch($id, $ref); if ($result <= 0) { dol_print_error($db, $object->error); exit(); } - + // fetch optionals attributes and labels $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - + if ($user->societe_id > 0 && $user->societe_id != $object->socid) accessforbidden('', 0); - + $result = $object->fetch_thirdparty(); - + $soc = new Societe($db); $soc->fetch($object->socid); $selleruserevenustamp = $mysoc->useRevenueStamp(); - + $totalpaye = $object->getSommePaiement(); $totalcreditnotes = $object->getSumCreditNotesUsed(); $totaldeposits = $object->getSumDepositsUsed(); // print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits." // selleruserrevenuestamp=".$selleruserevenustamp; - + // We can also use bcadd to avoid pb with floating points // For example print 239.2 - 229.3 - 9.9; does not return 0. // $resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT); // $resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT); $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); - + if ($object->paye) $resteapayer = 0; $resteapayeraffiche = $resteapayer; - + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice @@ -2245,43 +2270,43 @@ if ($action == 'create') { $filterabsolutediscount = "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')"; $filtercreditnote = "fk_facture_source IS NOT NULL AND description <> '(DEPOSIT)'"; } - + $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount); $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote); $absolute_discount = price2num($absolute_discount, 'MT'); $absolute_creditnote = price2num($absolute_creditnote, 'MT'); - + $author = new User($db); if ($object->user_author) { $author->fetch($object->user_author); } - + $objectidnext = $object->getIdReplacingInvoice(); - + $head = facture_prepare_head($object); - + dol_fiche_head($head, 'compta', $langs->trans('InvoiceCustomer'), 0, 'bill'); - + $formconfirm = ''; - + // Confirmation de la conversion de l'avoir en reduc if ($action == 'converttoreduc') { $text = $langs->trans('ConfirmConvertToReduc'); $formconfirm = $form->formconfirm($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('ConvertToReduc'), $text, 'confirm_converttoreduc', '', "yes", 2); } - + // Confirmation to delete invoice if ($action == 'delete') { $text = $langs->trans('ConfirmDeleteBill', $object->ref); $formquestion = array(); - + $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); } else { $qualified_for_stock_change = $object->hasProductsOrServices(1); } - + if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change && $object->statut >= 1) { $langs->load("stocks"); require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; @@ -2299,7 +2324,7 @@ if ($action == 'create') { $formconfirm = $form->formconfirm($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('DeleteBill'), $text, 'confirm_delete', '', '', 1); } } - + // Confirmation de la validation if ($action == 'valid') { // on verifie si l'objet est en numerotation provisoire @@ -2315,7 +2340,7 @@ if ($action == 'create') { } else { $numref = $object->ref; } - + $text = $langs->trans('ConfirmValidateBill', $numref); if (! empty($conf->notification->enabled)) { require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php'; @@ -2324,14 +2349,14 @@ if ($action == 'create') { $text .= $notify->confirmMessage('BILL_VALIDATE', $object->socid); } $formquestion = array(); - + $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); } else { $qualified_for_stock_change = $object->hasProductsOrServices(1); } - + if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) { $langs->load("stocks"); require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; @@ -2360,12 +2385,12 @@ if ($action == 'create') { } $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, (($object->type != Facture::TYPE_CREDIT_NOTE && $object->total_ttc < 0) ? "no" : "yes"), ($conf->notification->enabled ? 0 : 2)); } - + // Confirm back to draft status if ($action == 'modif') { $text = $langs->trans('ConfirmUnvalidateBill', $object->ref); $formquestion = array(); - + $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); @@ -2394,10 +2419,10 @@ if ($action == 'create') { // => 1), array('type' => 'other','name' => 'idwarehouse','label' => $label,'value' => $value)); } - + $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('UnvalidateBill'), $text, 'confirm_modif', $formquestion, "yes", 1); } - + // Confirmation du classement paye if ($action == 'paid' && $resteapayer <= 0) { $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $object->ref), 'confirm_paid', '', "yes", 1); @@ -2425,13 +2450,13 @@ if ($action == 'create') { foreach ($close as $key => $val) { $arrayreasons [$close [$key] ['code']] = $close [$key] ['reason']; } - + // Cree un tableau formulaire $formquestion = array('text' => $langs->trans("ConfirmClassifyPaidPartiallyQuestion"),array('type' => 'radio','name' => 'close_code','label' => $langs->trans("Reason"),'values' => $arrayreasons),array('type' => 'text','name' => 'close_note','label' => $langs->trans("Comment"),'value' => '','size' => '100')); // Paiement incomplet. On demande si motif = escompte ou autre $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidPartially', $object->ref), 'confirm_paid_partially', $formquestion, "yes"); } - + // Confirmation du classement abandonne if ($action == 'canceled') { // S'il y a une facture de remplacement pas encore validee (etat brouillon), @@ -2456,19 +2481,19 @@ if ($action == 'create') { // arrayreasons $arrayreasons [$close [1] ['code']] = $close [1] ['reason']; $arrayreasons [$close [2] ['code']] = $close [2] ['reason']; - + // Cree un tableau formulaire $formquestion = array('text' => $langs->trans("ConfirmCancelBillQuestion"),array('type' => 'radio','name' => 'close_code','label' => $langs->trans("Reason"),'values' => $arrayreasons),array('type' => 'text','name' => 'close_note','label' => $langs->trans("Comment"),'value' => '','size' => '100')); - + $formconfirm = $form->formconfirm($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('CancelBill'), $langs->trans('ConfirmCancelBill', $object->ref), 'confirm_canceled', $formquestion, "yes"); } } - + // Confirmation de la suppression d'une ligne produit if ($action == 'ask_deleteline') { $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1); } - + // Clone confirmation if ($action == 'clone') { // Create an array for form @@ -2479,22 +2504,22 @@ if ($action == 'create') { // Paiement incomplet. On demande si motif = escompte ou autre $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('CloneInvoice'), $langs->trans('ConfirmCloneInvoice', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); } - + if (! $formconfirm) { $parameters = array('lineid' => $lineid); $formconfirm = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by // hook } - + // Print form confirm print $formconfirm; - + // Invoice content - + print ''; - + $linkback = '' . $langs->trans("BackToList") . ''; - + // Ref print ''; print ''; - + // Ref customer print '
' . $langs->trans('Ref') . ''; @@ -2509,7 +2534,7 @@ if ($action == 'create') { } print $form->showrefnav($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref); print '
'; print ''; - + // Third party print '
'; @@ -2531,7 +2556,7 @@ if ($action == 'create') { print $object->ref_client; } print '
'; print ''; @@ -2559,7 +2584,7 @@ if ($action == 'create') { print ')'; } print ''; - + // Type print ''; - + // Relative and absolute discounts $addrelativediscount = '' . $langs->trans("EditRelativeDiscounts") . ''; $addabsolutediscount = '' . $langs->trans("EditGlobalDiscounts") . ''; $addcreditnote = '' . $langs->trans("AddCreditNote") . ''; - + print ''; - + // Date invoice print ''; - + // List of payments - + $sign = 1; if ($object->type == Facture::TYPE_CREDIT_NOTE) $sign = - 1; - + $nbrows = 8; $nbcols = 2; if (! empty($conf->projet->enabled)) @@ -2723,11 +2748,11 @@ if ($action == 'create') { $nbrows ++; if ($selleruserevenustamp) $nbrows ++; - + print ''; - + // Conditions de reglement print '
' . $langs->trans('Type') . ''; print $object->getLibType(); @@ -2573,7 +2598,7 @@ if ($action == 'create') { $facusing->fetch($object->fk_facture_source); print ' (' . $langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)) . ')'; } - + $facidavoir = $object->getListIdAvoirFromInvoice(); if (count($facidavoir) > 0) { print ' (' . $langs->transnoentities("InvoiceHasAvoir"); @@ -2595,12 +2620,12 @@ if ($action == 'create') { print ' (' . $langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)) . ')'; } print '
' . $langs->trans('Discounts'); print ''; if ($soc->remise_percent) @@ -2608,7 +2633,7 @@ if ($action == 'create') { else print $langs->trans("CompanyHasNoRelativeDiscount"); // print ' ('.$addrelativediscount.')'; - + if ($absolute_discount > 0) { print '. '; if ($object->statut > 0 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { @@ -2682,7 +2707,7 @@ if ($action == 'create') { // print '   -   '.$addcreditnote; // We disbale link to credit note // } print '
'; print ''; print '
'; @@ -2692,7 +2717,7 @@ if ($action == 'create') { print 'id . '">' . img_edit($langs->trans('SetDate'), 1) . '
'; print '
'; - + if ($object->type != Facture::TYPE_CREDIT_NOTE) { if ($action == 'editinvoicedate') { $form->form_date($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->date, 'invoicedate'); @@ -2703,13 +2728,13 @@ if ($action == 'create') { print dol_print_date($object->date, 'daytext'); } print ''; - + print ''; - + // List of payments already done print ''; print ''; @@ -2737,9 +2762,9 @@ if ($action == 'create') { print ''; print ''; print ''; - + $var = true; - + // Payments already done (from payment on this invoice) $sql = 'SELECT p.datep as dp, p.num_paiement, p.rowid, p.fk_bank,'; $sql .= ' c.code as payment_code, c.libelle as payment_label,'; @@ -2750,12 +2775,12 @@ if ($action == 'create') { $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid'; $sql .= ' WHERE pf.fk_facture = ' . $object->id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid'; $sql .= ' ORDER BY p.datep, p.tms'; - + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; - + // if ($object->type != 2) // { if ($num > 0) { @@ -2789,7 +2814,7 @@ if ($action == 'create') { } else { dol_print_error($db); } - + if ($object->type != Facture::TYPE_CREDIT_NOTE) { // Total already paid print ''; - + $resteapayeraffiche = $resteapayer; - + // Loop on each credit note or deposit amount applied $creditnoteamount = 0; $depositamount = 0; @@ -2836,7 +2861,7 @@ if ($action == 'create') { } else { dol_print_error($db); } - + // Paye partiellement 'escompte' if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'discount_vat') { print ''; $resteapayeraffiche = 0; } - + // Billed print ''; - + // Remainder to pay print ''; - + // Billed print ''; - + // Remainder to pay back print ''; print ''; print ''; - + // Sold credit note // print ''; // print ''; } - + print '
' . ($object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')) . '' . $langs->trans('Amount') . ' 
'; @@ -2798,9 +2823,9 @@ if ($action == 'create') { else print $langs->trans('AlreadyPaid'); print ' :' . price($totalpaye) . ' 
'; @@ -2868,10 +2893,10 @@ if ($action == 'create') { print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
' . $langs->trans("Billed") . ' :' . price($object->total_ttc) . ' 
'; if ($resteapayeraffiche >= 0) @@ -2887,10 +2912,10 @@ if ($action == 'create') { print '
'; print $langs->trans('AlreadyPaidBack'); print ' :' . price($sign * $totalpaye) . ' 
' . $langs->trans("Billed") . ' :' . price($sign * $object->total_ttc) . ' 
'; if ($resteapayeraffiche <= 0) @@ -2900,23 +2925,23 @@ if ($action == 'create') { print ' :' . price($sign * $resteapayeraffiche) . ' 
'.$langs->trans('TotalTTC').' :'.price($sign * // $object->total_ttc).' 
'; - + // Margin Infos if (! empty($conf->margin->enabled)) { print '
'; $object->displayMarginInfos($object->statut > 0); } - + print '
'; print ''; - + // Date payment term print '
'; @@ -2936,7 +2961,7 @@ if ($action == 'create') { print ' '; } print '
'; print ''; - + // Payment mode print '
'; @@ -2958,7 +2983,7 @@ if ($action == 'create') { print ' '; } print '
'; print ''; - + // Amount print ''; print ''; print ''; print ''; - + // Amount Local Taxes if ($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) // Localtax1 (example RE) { @@ -2992,7 +3017,7 @@ if ($action == 'create') { print ''; print ''; } - + // Revenue stamp if ($selleruserevenustamp) // Test company use revenue stamp { @@ -3017,20 +3042,20 @@ if ($action == 'create') { } print ''; } - + // Total with tax print ''; - + // Statut print ''; print ''; - + // Project if (! empty($conf->projet->enabled)) { $langs->load('projects'); print ''; print ''; print ''; } - + // Other attributes (TODO Move this into an include) $res = $object->fetch_optionals($object->id, $extralabels); $parameters = array('colspan' => ' colspan="2"'); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by // hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { - + foreach ($extrafields->attribute_label as $key => $label) { if ($action == 'edit_extras') { $value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]); @@ -3075,16 +3100,16 @@ if ($action == 'create') { if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) { $value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]); } - + if ($action == 'edit_extras' && $user->rights->facture->creer && GETPOST('attribute') == $key) { print ''; print ''; print ''; print ''; print ''; - + print $extrafields->showInputField($key, $value); - + print ''; print ''; } else { @@ -3096,75 +3121,75 @@ if ($action == 'create') { } } } - + print '
'; @@ -2974,13 +2999,13 @@ if ($action == 'create') { $form->form_modes_reglement($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->mode_reglement_id, 'none'); } print '
' . $langs->trans('AmountHT') . '' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . '
' . $langs->trans('AmountVAT') . '' . price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency) . '
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency) . '
' . $langs->trans('AmountTTC') . '' . price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency) . '
' . $langs->trans('Status') . '' . ($object->getLibStatut(4, $totalpaye)) . '
'; - + print ''; @@ -3040,7 +3065,7 @@ if ($action == 'create') { print ''; } print '
'; print $langs->trans('Project'); print '
'; - + print '
'; if ($action == 'classify') { $form->form_project($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->socid, $object->fk_project, 'projectid'); @@ -3050,14 +3075,14 @@ if ($action == 'create') { print '

'; - + if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { $blocname = 'contacts'; $title = $langs->trans('ContactsAddresses'); include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php'; } - + if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { $blocname = 'notes'; $title = $langs->trans('Notes'); include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php'; } - + // Lines $result = $object->getLinesArray(); - + print '
'; - + if (! empty($conf->use_javascript_ajax) && $object->statut == 0) { include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; } - + print ''; - + // Show object lines if (! empty($object->lines)) $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1); - + // Form to add new line if ($object->statut == 0 && $user->rights->facture->creer && $action != 'valid' && $action != 'editline') { $var = true; - + if ($conf->global->MAIN_FEATURES_LEVEL > 1) { // Add free or predefined products/services $object->formAddObjectLine(1, $mysoc, $soc); } else { // Add free products/services $object->formAddFreeProduct(1, $mysoc, $soc); - + // Add predefined products/services if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { $var = ! $var; $object->formAddPredefinedProduct(1, $mysoc, $soc); } } - + $parameters = array(); $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by // hook } - + print "
\n"; - + print "
\n"; - + dol_fiche_end(); - + // Boutons actions - + if ($action != 'prerelance' && $action != 'presend' && $action != 'valid' && $action != 'editline') { print '
'; - + $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been // modified by hook @@ -3173,7 +3198,7 @@ if ($action == 'create') { if ($object->statut == 1) { // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees $ventilExportCompta = $object->getVentilExportCompta(); - + if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0) { if (! $objectidnext) { if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->valider) || $user->rights->facture->invoice_advance->unvalidate) { @@ -3186,7 +3211,7 @@ if ($action == 'create') { } } } - + // Reopen a standard paid invoice if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && ($object->statut == Facture::TYPE_CREDIT_NOTE || $object->statut == Facture::TYPE_DEPOSIT) && $user->rights->facture->creer) // A paid // invoice @@ -3200,14 +3225,14 @@ if ($action == 'create') { print '
' . $langs->trans('ReOpen') . '
'; } } - + // Validate if ($object->statut == 0 && count($object->lines) > 0 && ((($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && (! empty($conf->global->FACTURE_ENABLE_NEGATIVE) || $object->total_ttc >= 0)) || ($object->type == Facture::TYPE_CREDIT_NOTE && $object->total_ttc <= 0))) { if ($user->rights->facture->valider) { print ''; } } - + // Send by mail if (($object->statut == 1 || $object->statut == 2)) { if ($objectidnext) { @@ -3219,7 +3244,7 @@ if ($action == 'create') { print ''; } } - + if (! empty($conf->global->FACTURE_SHOW_SEND_REMINDER)) // For backward compatibility { if (($object->statut == 1 || $object->statut == 2) && $resteapayer > 0) { @@ -3233,7 +3258,7 @@ if ($action == 'create') { } } } - + // Create payment if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) { if ($objectidnext) { @@ -3246,7 +3271,7 @@ if ($action == 'create') { } } } - + // Reverse back money or convert to reduction if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { // For credit note only @@ -3262,12 +3287,12 @@ if ($action == 'create') { print ''; } } - + // Classify paid (if not deposit and not credit note. Such invoice are "converted") if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement && (($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && $resteapayer <= 0) || ($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0))) { print ''; } - + // Classify 'closed not completely paid' (possible si validee et pas encore classee payee) if ($object->statut == 1 && $object->paye == 0 && $resteapayer > 0 && $user->rights->facture->paiement) { if ($totalpaye > 0 || $totalcreditnotes > 0) { @@ -3281,19 +3306,19 @@ if ($action == 'create') { } } } - + // Clone if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $user->rights->facture->creer) { print ''; } - + // Clone as predefined if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $object->statut == 0 && $user->rights->facture->creer) { if (! $objectidnext) { print ''; } } - + // Delete if ($user->rights->facture->supprimer) { if (! $object->is_erasable()) { @@ -3308,44 +3333,44 @@ if ($action == 'create') { } else { print ''; } - + print '
'; } } print '
'; - + if ($action != 'prerelance' && $action != 'presend') { print '
'; print ''; // ancre - + // Documents generes $filename = dol_sanitizeFileName($object->ref); $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref); $urlsource = $_SERVER ['PHP_SELF'] . '?facid=' . $object->id; $genallowed = $user->rights->facture->creer; $delallowed = $user->rights->facture->supprimer; - + print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang); $somethingshown = $formfile->numoffiles; - + // Linked object block $somethingshown = $object->showLinkedObjectBlock(); - + if (empty($somethingshown) && $object->statut > 0) { print '
' . $langs->trans('LinkedOrder') . ''; - + print ''; } - + // Link for paypal payment if (! empty($conf->paypal->enabled) && $object->statut != 0) { include_once DOL_DOCUMENT_ROOT . '/paypal/lib/paypal.lib.php'; print showPaypalPaymentUrl('invoice', $object->ref); } - + print '
'; - + // List of actions on element include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions = new FormActions($db); $somethingshown = $formactions->showactions($object, 'invoice', $socid); - + print '
'; } else { /* * Affiche formulaire mail */ - + // By default if $action=='presend' $titreform = 'SendBillByMail'; $topicmail = 'SendBillRef'; $modelmail = 'facture_send'; - + if ($action == 'prerelance') // For backward compatibility { $titrefrom = 'SendReminderBillByMail'; @@ -3415,12 +3440,12 @@ if ($action == 'create') { $action = 'relance'; } else $action = 'send'; - + $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/')); $file = $fileparams ['fullname']; - + // Build document if it not exists if (! $file || ! is_readable($file)) { // Define output language @@ -3434,7 +3459,7 @@ if ($action == 'create') { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } - + $result = facture_pdf_create($db, $object, GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result <= 0) { dol_print_error($db, $result); @@ -3443,10 +3468,10 @@ if ($action == 'create') { $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/')); $file = $fileparams ['fullname']; } - + print '
'; print_titre($langs->trans($titreform)); - + // Cree l'objet formulaire mail include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; $formmail = new FormMail($db); @@ -3477,43 +3502,43 @@ if ($action == 'create') { $formmail->substit ['__REFCLIENT__'] = $object->ref_client; $formmail->substit ['__PERSONALIZED__'] = ''; $formmail->substit ['__CONTACTCIVNAME__'] = ''; - + // Find the good contact adress $custcontact = ''; $contactarr = array(); $contactarr = $object->liste_contact(- 1, 'external'); - + if (is_array($contactarr) && count($contactarr) > 0) { foreach ($contactarr as $contact) { if ($contact ['libelle'] == $langs->trans('TypeContact_facture_external_BILLING')) { - + require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; - + $contactstatic = new Contact($db); $contactstatic->fetch($contact ['id']); $custcontact = $contactstatic->getFullName($langs, 1); } } - + if (! empty($custcontact)) { $formmail->substit ['__CONTACTCIVNAME__'] = $custcontact; } } - + // Tableau des parametres complementaires du post $formmail->param ['action'] = $action; $formmail->param ['models'] = $modelmail; $formmail->param ['facid'] = $object->id; $formmail->param ['returnurl'] = $_SERVER ["PHP_SELF"] . '?id=' . $object->id; - + // Init list of files if (GETPOST("mode") == 'init') { $formmail->clear_attached_files(); $formmail->add_attached_files($file, basename($file), dol_mimetype($file)); } - + print $formmail->get_form(); - + print '
'; } }