--- /tmp/dsg/dolibarr/htdocs/fourn/facture/github_19.0.3_card.php +++ /tmp/dsg/dolibarr/htdocs/fourn/facture/client_card.php @@ -3 +3 @@ - * Copyright (C) 2004-2020 Laurent Destailleur + * Copyright (C) 2004-2016 Laurent Destailleur @@ -8 +8 @@ - * Copyright (C) 2013-2022 Philippe Grand + * Copyright (C) 2013-2015 Philippe Grand @@ -11,2 +11,2 @@ - * Copyright (C) 2016-2023 Alexandre Spangaro - * Copyright (C) 2018-2023 Frédéric France + * Copyright (C) 2016-2017 Alexandre Spangaro + * Copyright (C) 2018-2019 Frédéric France @@ -14,2 +13,0 @@ - * Copyright (C) 2022 Gauthier VERDOL - * Copyright (C) 2023 Nick Fragoulis @@ -37 +34,0 @@ -// Load Dolibarr environment @@ -43 +39,0 @@ -require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture-rec.class.php'; @@ -48 +43,0 @@ -require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; @@ -50 +45 @@ -if (isModEnabled("product")) { +if (!empty($conf->product->enabled)) { @@ -54 +49 @@ -if (isModEnabled('project')) { +if (!empty($conf->projet->enabled)) { @@ -59 +54 @@ -if (isModEnabled('variants')) { +if (!empty($conf->variants->enabled)) { @@ -62,9 +57,5 @@ -if (isModEnabled('accounting')) { - require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; -} - - -$langs->loadLangs(array('bills', 'compta', 'suppliers', 'companies', 'products', 'banks', 'admin')); -if (isModEnabled('incoterm')) { - $langs->load('incoterm'); -} +if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; + + +$langs->loadLangs(array('bills', 'compta', 'suppliers', 'companies', 'products', 'banks')); +if (!empty($conf->incoterm->enabled)) $langs->load('incoterm'); @@ -73 +64 @@ - +$socid = GETPOST('socid', 'int'); @@ -78,3 +68,0 @@ -$backtopage = GETPOST('backtopage', 'alpha'); -$backtopageforcancel = ''; - @@ -85,2 +72,0 @@ -$fac_recid = GETPOST('fac_rec', 'int'); -$rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1; @@ -89,3 +75,3 @@ -$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0)); -$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0)); -$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0)); +$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)); +$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); @@ -103 +89,2 @@ -if ($id > 0 || !empty($ref)) { +if ($id > 0 || !empty($ref)) +{ @@ -105,3 +92 @@ - if ($ret < 0) { - dol_print_error($db, $object->error); - } + if ($ret < 0) dol_print_error($db, $object->error); @@ -109,3 +94 @@ - if ($ret < 0) { - dol_print_error($db, $object->error); - } + if ($ret < 0) dol_print_error($db, $object->error); @@ -115,5 +98,2 @@ -$socid = GETPOST('socid', 'int'); -if (!empty($user->socid)) { - $socid = $user->socid; -} - +$socid = ''; +if (!empty($user->socid)) $socid = $user->socid; @@ -123,17 +103,6 @@ -// Common permissions -$usercanread = ($user->hasRight("fournisseur", "facture", "lire") || $user->hasRight("supplier_invoice", "lire")); -$usercancreate = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); -$usercandelete = ($user->hasRight("fournisseur", "facture", "supprimer") || $user->hasRight("supplier_invoice", "supprimer")); -$usercancreatecontract = $user->hasRight("contrat", "creer"); - -// Advanced permissions -$usercanvalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "supplier_invoice_advance", "validate"))); -$usercansend = (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight("fournisseur", "supplier_invoice_advance", "send")); - -// Permissions for includes -$permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php -$permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php -$permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php -$permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php - -$error = 0; +$usercancreate = $user->rights->fournisseur->facture->creer; + +$permissionnote = $user->rights->fournisseur->facture->creer; // Used by the include of actions_setnotes.inc.php +$permissiondellink = $user->rights->fournisseur->facture->creer; // Used by the include of actions_dellink.inc.php +$permissiontoedit = $user->rights->fournisseur->facture->creer; // Used by the include of actions_lineupdown.inc.php +$permissiontoadd = $user->rights->fournisseur->facture->creer; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php @@ -148,22 +117,8 @@ -if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -} - -if (empty($reshook)) { - $backurlforlist = DOL_URL_ROOT.'/fourn/facture/list.php'; - - if (empty($backtopage) || ($cancel && empty($id))) { - if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { - if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) { - $backtopage = $backurlforlist; - } else { - $backtopage = DOL_URL_ROOT.'/fourn/facture/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__'); - } - } - } - - if ($cancel) { - if (!empty($backtopageforcancel)) { - header("Location: ".$backtopageforcancel); - exit; - } elseif (!empty($backtopage)) { +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if (empty($reshook)) +{ + if ($cancel) + { + if (!empty($backtopage)) + { @@ -183 +138,2 @@ - if (GETPOST('linkedOrder') && empty($cancel) && $id > 0) { + if (GETPOST('linkedOrder') && empty($cancel) && $id > 0) + { @@ -190,18 +146,26 @@ - 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. - - if (GETPOST('newsupplierref', 'alphanohtml')) { - $objectutil->ref_supplier = GETPOST('newsupplierref', 'alphanohtml'); - } - $objectutil->date = dol_mktime(12, 0, 0, GETPOST('newdatemonth', 'int'), GETPOST('newdateday', 'int'), GETPOST('newdateyear', 'int')); - - $result = $objectutil->createFromClone($user, $id); - if ($result > 0) { - header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); - exit; - } else { - $langs->load("errors"); - setEventMessages($objectutil->error, $objectutil->errors, 'errors'); - $action = ''; - } - } elseif ($action == 'confirm_valid' && $confirm == 'yes' && $usercanvalidate) { + 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. + + if (GETPOST('newsupplierref', 'alphanohtml')) $objectutil->ref_supplier = GETPOST('newsupplierref', 'alphanohtml'); + $objectutil->date = dol_mktime(12, 0, 0, GETPOST('newdatemonth', 'int'), GETPOST('newdateday', 'int'), GETPOST('newdateyear', 'int')); + + $result = $objectutil->createFromClone($user, $id); + if ($result > 0) + { + header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); + exit; + } + else + { + $langs->load("errors"); + setEventMessages($objectutil->error, $objectutil->errors, 'errors'); + $action = ''; + } + } + + elseif ($action == 'confirm_valid' && $confirm == 'yes' && + ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->facture->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate))) + ) + { @@ -214 +178,2 @@ - if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) + { @@ -216 +181,3 @@ - } else { + } + else + { @@ -221 +188,2 @@ - if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) { + if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) + { @@ -223 +191,2 @@ - if (!$idwarehouse || $idwarehouse == -1) { + if (!$idwarehouse || $idwarehouse == -1) + { @@ -230,3 +199,2 @@ - if (!$error) { - $db->begin(); - + if (!$error) + { @@ -234,3 +202,2 @@ - if ($result < 0) { - $db->rollback(); - + if ($result < 0) + { @@ -239,2 +205,0 @@ - $db->commit(); - @@ -242 +207,2 @@ - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { @@ -245,6 +211,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; @@ -255 +217 @@ - $model = $object->model_pdf; + $model = $object->modelpdf; @@ -259,7 +221,8 @@ - if ($result < 0) { - dol_print_error($db, $result); - } - } - } - } - } elseif ($action == 'confirm_delete' && $confirm == 'yes') { + if ($result < 0) dol_print_error($db, $result); + } + } + } + } + + elseif ($action == 'confirm_delete' && $confirm == 'yes') + { @@ -271,41 +234,19 @@ - if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) { - $revertstock = GETPOST('revertstock'); - - if ($revertstock) { - $idwarehouse = GETPOST('idwarehouse'); - - $qualified_for_stock_change = 0; - if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { - $qualified_for_stock_change = $object->hasProductsOrServices(2); - } else { - $qualified_for_stock_change = $object->hasProductsOrServices(1); - } - - // Check parameters - if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) { - $langs->load("stocks"); - if (!$idwarehouse || $idwarehouse == -1) { - $error++; - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); - $action = 'delete'; - } else { - $result = $object->setDraft($user, $idwarehouse); - if ($result < 0) { - $error++; - } - } - } - } - - if (!$error) { - $result = $object->delete($user); - if ($result > 0) { - header('Location: list.php?restore_lastsearch_values=1'); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - } - } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) { - // Remove a product line + if (($user->rights->fournisseur->facture->supprimer && $isErasable > 0) + || ($user->rights->fournisseur->facture->creer && $isErasable == 1)) + { + $result = $object->delete($user); + if ($result > 0) + { + header('Location: list.php?restore_lastsearch_values=1'); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } + + // Remove a product line + elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) + { @@ -313,3 +254,2 @@ - if ($result > 0) { - // reorder lines - $object->line_order(true); + if ($result > 0) + { @@ -319 +259 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id','aZ09')) + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) @@ -321 +261 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) @@ -322,0 +263,57 @@ + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + $ret = $object->fetch($object->id); // Reload to get new records + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + }*/ + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + /* Fix bug 1485 : Reset action to avoid asking again confirmation on failure */ + $action = ''; + } + } + + // Delete link of credit note to invoice + elseif ($action == 'unlinkdiscount' && $user->rights->fournisseur->facture->creer) + { + $discount = new DiscountAbsolute($db); + $result = $discount->fetch(GETPOST("discountid")); + $discount->unlink_invoice(); + } + + elseif ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) + { + $object->fetch($id); + $result = $object->set_paid($user); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + // Set supplier ref + if ($action == 'setref_supplier' && $user->rights->fournisseur->facture->creer) + { + $object->ref_supplier = GETPOST('ref_supplier', 'alpha'); + + if ($object->update($user) < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + else + { + // Define output language + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } @@ -329,16 +326,41 @@ - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - }*/ - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - /* Fix bug 1485 : Reset action to avoid asking again confirmation on failure */ - $action = ''; - } - } elseif ($action == 'unlinkdiscount' && $usercancreate) { - // Delete link of credit note to invoice - $discount = new DiscountAbsolute($db); - $result = $discount->fetch(GETPOSTINT("discountid")); - $discount->unlink_invoice(); - } elseif ($action == 'confirm_paid' && $confirm == 'yes' && $usercancreate) { + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + } + + // payments conditions + if ($action == 'setconditions' && $user->rights->fournisseur->facture->creer) + { + $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); + } + + // Set incoterm + elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) + { + $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); + } + + // payment mode + elseif ($action == 'setmode' && $user->rights->fournisseur->facture->creer) + { + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); + } + + // Multicurrency Code + elseif ($action == 'setmulticurrencycode' && $user->rights->fournisseur->facture->creer) { + $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); + } + + // Multicurrency rate + elseif ($action == 'setmulticurrencyrate' && $user->rights->fournisseur->facture->creer) { + $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx', 'alpha'))); + } + + // bank account + elseif ($action == 'setbankaccount' && $user->rights->fournisseur->facture->creer) { + $result = $object->setBankAccount(GETPOST('fk_account', 'int')); + } + + // Set label + elseif ($action == 'setlabel' && $user->rights->fournisseur->facture->creer) + { @@ -346,6 +368,13 @@ - $result = $object->setPaid($user); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - } elseif ($action == 'confirm_paid_partially' && $confirm == 'yes') { - // Classif "paid partialy" + $object->label = GETPOST('label'); + $result = $object->update($user); + if ($result < 0) dol_print_error($db); + } + elseif ($action == 'setdatef' && $user->rights->fournisseur->facture->creer) + { + $newdate = dol_mktime(0, 0, 0, $_POST['datefmonth'], $_POST['datefday'], $_POST['datefyear']); + if ($newdate > (dol_now() + (empty($conf->global->INVOICE_MAX_OFFSET_IN_FUTURE) ? 0 : $conf->global->INVOICE_MAX_OFFSET_IN_FUTURE))) + { + if (empty($conf->global->INVOICE_MAX_OFFSET_IN_FUTURE)) setEventMessages($langs->trans("WarningInvoiceDateInFuture"), null, 'warnings'); + else setEventMessages($langs->trans("WarningInvoiceDateTooFarInFuture"), null, 'warnings'); + } + @@ -353,12 +382,17 @@ - $close_code = GETPOST("close_code", 'restricthtml'); - $close_note = GETPOST("close_note", 'restricthtml'); - if ($close_code) { - $result = $object->setPaid($user, $close_code, $close_note); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), null, 'errors'); - } - } elseif ($action == 'confirm_canceled' && $confirm == 'yes') { - // Classify "abandoned" + + $object->date = $newdate; + $date_echence_calc = $object->calculate_date_lim_reglement(); + if (!empty($object->date_echeance) && $object->date_echeance < $date_echence_calc) + { + $object->date_echeance = $date_echence_calc; + } + if ($object->date_echeance && $object->date_echeance < $object->date) + { + $object->date_echeance = $object->date; + } + + $result = $object->update($user); + if ($result < 0) dol_print_error($db, $object->error); + } + elseif ($action == 'setdate_lim_reglement' && $user->rights->fournisseur->facture->creer) + { @@ -366,20 +400,52 @@ - $close_code = GETPOST("close_code", 'restricthtml'); - $close_note = GETPOST("close_note", 'restricthtml'); - if ($close_code) { - $result = $object->setCanceled($user, $close_code, $close_note); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), null, 'errors'); - } - } - - // Set supplier ref - if ($action == 'setref_supplier' && $usercancreate) { - $object->ref_supplier = GETPOST('ref_supplier', 'alpha'); - - if ($object->update($user) < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - // Define output language + $object->date_echeance = dol_mktime(12, 0, 0, $_POST['date_lim_reglementmonth'], $_POST['date_lim_reglementday'], $_POST['date_lim_reglementyear']); + if (!empty($object->date_echeance) && $object->date_echeance < $object->date) + { + $object->date_echeance = $object->date; + setEventMessages($langs->trans("DatePaymentTermCantBeLowerThanObjectDate"), null, 'warnings'); + } + $result = $object->update($user); + if ($result < 0) dol_print_error($db, $object->error); + } + elseif ($action == "setabsolutediscount" && $usercancreate) + { + // POST[remise_id] or POST[remise_id_for_payment] + + // We use the credit to reduce amount of invoice + if (!empty($_POST["remise_id"])) { + $ret = $object->fetch($id); + if ($ret > 0) { + $result = $object->insert_discount($_POST["remise_id"]); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } else { + dol_print_error($db, $object->error); + } + } + // We use the credit to reduce remain to pay + if (!empty($_POST["remise_id_for_payment"])) + { + require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; + $discount = new DiscountAbsolute($db); + $discount->fetch($_POST["remise_id_for_payment"]); + + //var_dump($object->getRemainToPay(0)); + //var_dump($discount->amount_ttc);exit; + if (price2num($discount->amount_ttc) > price2num($object->getRemainToPay(0))) + { + // TODO Split the discount in 2 automatically + $error++; + setEventMessages($langs->trans("ErrorDiscountLargerThanRemainToPaySplitItBefore"), null, 'errors'); + } + + if (!$error) + { + $result = $discount->link_to_invoice(0, $id); + if ($result < 0) { + setEventMessages($discount->error, $discount->errors, 'errors'); + } + } + } + + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { @@ -388,6 +454,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; @@ -398,174 +459,0 @@ - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - $ret = $object->fetch($object->id); // Reload to get new records - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - } - - // payments conditions - if ($action == 'setconditions' && $usercancreate) { - $object->fetch($id); - $object->cond_reglement_code = 0; // To clean property - $object->cond_reglement_id = 0; // To clean property - - $error = 0; - - $db->begin(); - - if (!$error) { - $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); - if ($result < 0) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - if (!$error) { - $new_date_echeance = $object->calculate_date_lim_reglement(); - if ($new_date_echeance) { - $object->date_echeance = $new_date_echeance; - } - if ($object->date_echeance < $object->date) { - $object->date_echeance = $object->date; - } - $result = $object->update($user); - if ($result < 0) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - if ($error) { - $db->rollback(); - } else { - $db->commit(); - } - } elseif ($action == 'set_incoterms' && isModEnabled('incoterm')) { - // Set incoterm - $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); - } elseif ($action == 'setmode' && $usercancreate) { - // payment mode - $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); - } elseif ($action == 'setmulticurrencycode' && $usercancreate) { - // Multicurrency Code - $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); - } elseif ($action == 'setmulticurrencyrate' && $usercancreate) { - // Multicurrency rate - $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx', 'alpha')), GETPOST('calculation_mode', 'int')); - } elseif ($action == 'setbankaccount' && $usercancreate) { - // bank account - $result = $object->setBankAccount(GETPOST('fk_account', 'int')); - } elseif ($action == 'setvatreversecharge' && $usercancreate) { - // vat reverse charge - $vatreversecharge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0; - $result = $object->setVATReverseCharge($vatreversecharge); - } - - if ($action == 'settransportmode' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { - // transport mode - $result = $object->setTransportMode(GETPOST('transport_mode_id', 'int')); - } elseif ($action == 'setlabel' && $usercancreate) { - // Set label - $object->fetch($id); - $object->label = GETPOST('label'); - $result = $object->update($user); - if ($result < 0) { - dol_print_error($db); - } - } elseif ($action == 'setdatef' && $usercancreate) { - $newdate = dol_mktime(0, 0, 0, GETPOST('datefmonth', 'int'), GETPOST('datefday', 'int'), GETPOST('datefyear', 'int'), 'tzserver'); - if ($newdate > (dol_now('tzuserrel') + (!getDolGlobalString('INVOICE_MAX_FUTURE_DELAY') ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { - if (!getDolGlobalString('INVOICE_MAX_FUTURE_DELAY')) { - setEventMessages($langs->trans("WarningInvoiceDateInFuture"), null, 'warnings'); - } else { - setEventMessages($langs->trans("WarningInvoiceDateTooFarInFuture"), null, 'warnings'); - } - } - - $object->fetch($id); - - $object->date = $newdate; - $date_echence_calc = $object->calculate_date_lim_reglement(); - if (!empty($object->date_echeance)) { - $object->date_echeance = $date_echence_calc; - } - if ($object->date_echeance && $object->date_echeance < $object->date) { - $object->date_echeance = $object->date; - } - - $result = $object->update($user); - if ($result < 0) { - dol_print_error($db, $object->error); - } - } elseif ($action == 'setdate_lim_reglement' && $usercancreate) { - $object->fetch($id); - $object->date_echeance = dol_mktime(12, 0, 0, GETPOST('date_lim_reglementmonth', 'int'), GETPOST('date_lim_reglementday', 'int'), GETPOST('date_lim_reglementyear', 'int')); - if (!empty($object->date_echeance) && $object->date_echeance < $object->date) { - $object->date_echeance = $object->date; - setEventMessages($langs->trans("DatePaymentTermCantBeLowerThanObjectDate"), null, 'warnings'); - } - $result = $object->update($user); - if ($result < 0) { - dol_print_error($db, $object->error); - } - } elseif ($action == "setabsolutediscount" && $usercancreate) { - $db->begin(); - // We use the credit to reduce amount of invoice - if (GETPOST("remise_id", "int")) { - $ret = $object->fetch($id); - if ($ret > 0) { - $result = $object->insert_discount(GETPOST("remise_id", "int")); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - dol_print_error($db, $object->error); - } - } - // We use the credit to reduce remain to pay - if (GETPOST("remise_id_for_payment", "int")) { - require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; - $discount = new DiscountAbsolute($db); - $discount->fetch(GETPOST("remise_id_for_payment", "int")); - - //var_dump($object->getRemainToPay(0)); - //var_dump($discount->amount_ttc);exit; - $remaintopay = $object->getRemainToPay(0); - if (price2num($discount->amount_ttc) > price2num($remaintopay)) { - // TODO Split the discount in 2 automatically - $error++; - setEventMessages($langs->trans("ErrorDiscountLargerThanRemainToPaySplitItBefore"), null, 'errors'); - } - - if (!$error) { - $result = $discount->link_to_invoice(0, $id); - if ($result < 0) { - $error++; - setEventMessages($discount->error, $discount->errors, 'errors'); - } - } - if (!$error) { - $newremaintopay = $object->getRemainToPay(0); - if ($newremaintopay == 0) { - $object->setPaid($user); - } - } - } - if (!$error) { - $db->commit(); - } else { - $db->rollback(); - } - if (empty($error) && !getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - $outputlangs = $langs; - $newlang = ''; - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } @@ -574,7 +462,7 @@ - $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - } elseif ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $usercancreate) { - // Convertir en reduc + $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + } + } + // Convertir en reduc + elseif ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $usercancreate) + { @@ -590,7 +478,4 @@ - if ($object->type == FactureFournisseur::TYPE_DEPOSIT && empty($discountcheck->id)) { - $canconvert = 1; // we can convert deposit into discount if deposit is paid (completely, partially or not at all) and not already converted (see real condition into condition used to show button converttoreduc) - } - if (($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_STANDARD) && $object->paye == 0 && empty($discountcheck->id)) { - $canconvert = 1; // we can convert credit note into discount if credit note is not refunded completely and not already converted and amount of payment is 0 (see also the real condition used as the condition to show button converttoreduc) - } - if ($canconvert) { + if ($object->type == FactureFournisseur::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 == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_STANDARD) && $object->paye == 0 && empty($discountcheck->id)) $canconvert = 1; // we can convert credit note into discount if credit note is not refunded completely and not already converted and amount of payment is 0 (see also the real condition used as the condition to show button converttoreduc) + if ($canconvert) + { @@ -604,10 +489,7 @@ - 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; - $amount_tva[$keyforvatrate] += $line->total_tva; - $amount_ttc[$keyforvatrate] += $line->total_ttc; - $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht; - $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva; - $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc; + 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 + { // no need to create discount if amount is null + $amount_ht[$line->tva_tx] += $line->total_ht; + $amount_tva[$line->tva_tx] += $line->total_tva; + $amount_ttc[$line->tva_tx] += $line->total_ttc; @@ -619 +501 @@ - if (getDolGlobalString('SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') && $object->type == FactureFournisseur::TYPE_CREDIT_NOTE) { + if (!empty($conf->global->SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED)) { @@ -627,3 +508,0 @@ - $multicurrency_amount_ht[$vatrate] = price2num($multicurrency_amount_ht[$vatrate] * $ratio, 'MU'); - $multicurrency_amount_tva[$vatrate] = price2num($multicurrency_amount_tva[$vatrate] * $ratio, 'MU'); - $multicurrency_amount_ttc[$vatrate] = price2num($multicurrency_amount_ttc[$vatrate] * $ratio, 'MU'); @@ -637 +516 @@ - if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) { + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) @@ -639 +518 @@ - } elseif ($object->type == FactureFournisseur::TYPE_DEPOSIT) { + elseif ($object->type == FactureFournisseur::TYPE_DEPOSIT) @@ -641 +520 @@ - } elseif ($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_REPLACEMENT || $object->type == FactureFournisseur::TYPE_SITUATION) { + elseif ($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_REPLACEMENT || $object->type == FactureFournisseur::TYPE_SITUATION) @@ -643 +522 @@ - } else { + else { @@ -652 +531,2 @@ - if ($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_REPLACEMENT || $object->type == FactureFournisseur::TYPE_SITUATION) { + if ($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_REPLACEMENT || $object->type == FactureFournisseur::TYPE_SITUATION) + { @@ -659 +539 @@ - $sql .= ' WHERE pf.fk_facturefourn = '.((int) $object->id); + $sql .= ' WHERE pf.fk_facturefourn = '.$object->id; @@ -664,3 +544 @@ - if (!$resql) { - dol_print_error($db); - } + if (!$resql) dol_print_error($db); @@ -676 +554 @@ - $sql .= " WHERE fk_invoice_supplier = ".((int) $object->id); + $sql .= " WHERE fk_invoice_supplier = ".$object->id; @@ -682,3 +560 @@ - } else { - dol_print_error($db); - } + } else dol_print_error($db); @@ -689 +564,0 @@ - $discount->vat_src_code = ''; @@ -692 +567,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -696,2 +572,4 @@ - if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_DEPOSIT) { - foreach ($amount_ht as $tva_tx => $xxx) { + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_DEPOSIT) + { + foreach ($amount_ht as $tva_tx => $xxx) + { @@ -701,12 +578,0 @@ - $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]); - $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]); - $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]); - - // Clean vat code - $reg = array(); - $vat_src_code = ''; - if (preg_match('/\((.*)\)/', $tva_tx, $reg)) { - $vat_src_code = $reg[1]; - $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx); // Remove code into vatrate. - } - @@ -714 +579,0 @@ - $discount->vat_src_code = $vat_src_code; @@ -717 +582,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -724 +590,2 @@ - if (empty($error)) { + if (empty($error)) + { @@ -727,2 +594,3 @@ - $result = $object->setPaid($user); - if ($result >= 0) { + $result = $object->set_paid($user); + if ($result >= 0) + { @@ -730 +598,3 @@ - } else { + } + else + { @@ -737 +607,3 @@ - } else { + } + else + { @@ -742,4 +614,9 @@ - } elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercancreate) { - // Delete payment - $object->fetch($id); - if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0) { + } + + + // Delete payment + elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) + { + $object->fetch($id); + if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0) + { @@ -749,5 +626,2 @@ - $result = $paiementfourn->delete(); - if ($result > 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); - exit; - } + $result = $paiementfourn->delete(); // If fetch ok and found + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); @@ -759,6 +633,6 @@ - } elseif ($action == 'add' && $usercancreate) { - // Insert new invoice in database - if ($socid > 0) { - $object->socid = GETPOST('socid', 'int'); - } - $selectedLines = GETPOST('toselect', 'array'); + } + + // Create + elseif ($action == 'add' && $usercancreate) + { + if ($socid > 0) $object->socid = GETPOST('socid', 'int'); @@ -772,10 +646,4 @@ - if ($ret < 0) { - $error++; - } - - $dateinvoice = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server - $datedue = dol_mktime(0, 0, 0, GETPOST('echmonth', 'int'), GETPOST('echday', 'int'), GETPOST('echyear', 'int'), 'tzserver'); - //var_dump($dateinvoice.' '.dol_print_date($dateinvoice, 'dayhour')); - //var_dump(dol_now('tzuserrel').' '.dol_get_last_hour(dol_now('tzuserrel')).' '.dol_print_date(dol_now('tzuserrel'),'dayhour').' '.dol_print_date(dol_get_last_hour(dol_now('tzuserrel')), 'dayhour')); - //var_dump($db->idate($dateinvoice)); - //exit; + if ($ret < 0) $error++; + + $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); + $datedue = dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear']); @@ -784,7 +652,4 @@ - if (GETPOST('type', 'int') === '') { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); - $error++; - } - - if (GETPOST('type') == FactureFournisseur::TYPE_REPLACEMENT) { - if (empty($dateinvoice)) { + if ($_POST['type'] == FactureFournisseur::TYPE_REPLACEMENT) + { + if ($datefacture == '') + { @@ -795,6 +660 @@ - } elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (!getDolGlobalString('INVOICE_MAX_FUTURE_DELAY') ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { - $error++; - setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); - $action = 'create'; - } - + } @@ -811 +671 @@ - $object->ref = GETPOST('ref', 'alphanohtml'); + $object->ref = GETPOST('ref', 'nohtml'); @@ -814,3 +674,2 @@ - $object->libelle = GETPOST('label', 'alphanohtml'); // deprecated - $object->label = GETPOST('label', 'alphanohtml'); - $object->date = $dateinvoice; + $object->libelle = GETPOST('label', 'nohtml'); + $object->date = $datefacture; @@ -818,4 +677,4 @@ - $object->note_public = GETPOST('note_public', 'restricthtml'); - $object->note_private = GETPOST('note_private', 'restricthtml'); - $object->cond_reglement_id = GETPOST('cond_reglement_id', 'int'); - $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int'); + $object->note_public = GETPOST('note_public', 'none'); + $object->note_private = GETPOST('note_private', 'none'); + $object->cond_reglement_id = GETPOST('cond_reglement_id'); + $object->mode_reglement_id = GETPOST('mode_reglement_id'); @@ -823 +681,0 @@ - $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0; @@ -829 +686,0 @@ - $object->transport_mode_id = GETPOST('transport_mode_id', 'int'); @@ -832 +689 @@ - $object->fk_facture_source = GETPOST('fac_replacement', 'int'); + $object->fk_facture_source = GETPOST('fac_replacement'); @@ -844 +701,2 @@ - if (GETPOST('type') == FactureFournisseur::TYPE_CREDIT_NOTE) { + if ($_POST['type'] == FactureFournisseur::TYPE_CREDIT_NOTE) + { @@ -846 +704,2 @@ - if (!($sourceinvoice > 0) && !getDolGlobalString('INVOICE_CREDIT_NOTE_STANDALONE')) { + if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) + { @@ -850 +709,2 @@ - if (GETPOST('socid', 'int') < 1) { + if (GETPOST('socid', 'int') < 1) + { @@ -855,2 +715,2 @@ - - if (empty($dateinvoice)) { + if ($datefacture == '') + { @@ -861,8 +721,4 @@ - } elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (!getDolGlobalString('INVOICE_MAX_FUTURE_DELAY') ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { - $error++; - setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); - $action = 'create'; - } - - if (!GETPOST('ref_supplier')) { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('RefSupplierBill')), null, 'errors'); + } + if (!GETPOST('ref_supplier')) + { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('RefSupplier')), null, 'errors'); @@ -874,7 +730,2 @@ - if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED') && empty(GETPOST("subtype"))) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InvoiceSubtype")), null, 'errors'); - $action = 'create'; - } - - if (!$error) { + if (!$error) + { @@ -884,3 +735,2 @@ - $object->ref = GETPOST('ref', 'alphanohtml'); - $object->ref_supplier = GETPOST('ref_supplier', 'alphanohtml'); - $object->subtype = GETPOST('subtype', 'alphanohtml'); + $object->ref = GETPOST('ref', 'nohtml'); + $object->ref_supplier = GETPOST('ref_supplier', 'nohtml'); @@ -888,6 +738,6 @@ - $object->libelle = GETPOST('label', 'alphanohtml'); - $object->label = GETPOST('label', 'alphanohtml'); - $object->date = $dateinvoice; - $object->date_echeance = $datedue; - $object->note_public = GETPOST('note_public', 'restricthtml'); - $object->note_private = GETPOST('note_private', 'restricthtml'); + $object->libelle = GETPOST('label', 'nohtml'); + $object->label = GETPOST('label', 'nohtml'); + $object->date = $datefacture; + $object->date_echeance = $datedue; + $object->note_public = GETPOST('note_public', 'none'); + $object->note_private = GETPOST('note_private', 'none'); @@ -897 +746,0 @@ - $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0; @@ -899 +748 @@ - $object->fk_incoterms = GETPOST('incoterm_id', 'int'); + $object->fk_incoterms = GETPOST('incoterm_id', 'int'); @@ -902,2 +751 @@ - $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); - $object->transport_mode_id = GETPOST('transport_mode_id', 'int'); + $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); @@ -915 +763,2 @@ - if (GETPOST('invoiceAvoirWithLines', 'int') == 1 && $id > 0) { + if (GETPOST('invoiceAvoirWithLines', 'int') == 1 && $id > 0) + { @@ -917 +766,2 @@ - if ($facture_source->fetch($object->fk_facture_source) > 0) { + if ($facture_source->fetch($object->fk_facture_source) > 0) + { @@ -920 +770,2 @@ - foreach ($facture_source->lines as $line) { + foreach ($facture_source->lines as $line) + { @@ -951 +802,2 @@ - if (GETPOST('invoiceAvoirWithPaymentRestAmount', 'int') == 1 && $id > 0) { + if (GETPOST('invoiceAvoirWithPaymentRestAmount', 'int') == 1 && $id > 0) + { @@ -953,2 +805,3 @@ - if ($facture_source->fetch($object->fk_facture_source) > 0) { - $totalpaid = $facture_source->getSommePaiement(); + if ($facture_source->fetch($object->fk_facture_source) > 0) + { + $totalpaye = $facture_source->getSommePaiement(); @@ -957,62 +810,13 @@ - $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits); - $desc = $langs->trans('invoiceAvoirLineWithPaymentRestAmount'); - $retAddLine = $object->addline($desc, $remain_to_pay, 0, 0, 0, 1, 0, 0, '', '', 0, '', 'TTC'); - - if ($retAddLine < 0) { - $error++; - } - } - } - } - } elseif ($fac_recid > 0 && (GETPOST('type') == FactureFournisseur::TYPE_STANDARD || GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT)) { - // Standard invoice or Deposit invoice, created from a Predefined template invoice - if (empty($dateinvoice)) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); - $action = 'create'; - } elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (!getDolGlobalString('INVOICE_MAX_FUTURE_DELAY') ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { - $error++; - setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); - $action = 'create'; - } - - if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED') && empty(GETPOST("subtype"))) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InvoiceSubtype")), null, 'errors'); - $action = 'create'; - } - - if (!$error) { - $object->socid = GETPOST('socid', 'int'); - $object->type = GETPOST('type', 'alphanohtml'); - $object->subtype = GETPOST('subtype', 'alphanohtml'); - $object->ref = GETPOST('ref', 'alphanohtml'); - $object->date = $dateinvoice; - $object->note_public = trim(GETPOST('note_public', 'restricthtml')); - $object->note_private = trim(GETPOST('note_private', 'restricthtml')); - $object->ref_supplier = GETPOST('ref_supplier', 'alphanohtml'); - $object->model_pdf = GETPOST('model', 'alphanohtml'); - $object->fk_project = GETPOST('projectid', 'int'); - $object->cond_reglement_id = (GETPOST('type') == 3 ? 1 : GETPOST('cond_reglement_id')); - $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int'); - $object->fk_account = GETPOST('fk_account', 'int'); - $object->amount = price2num(GETPOST('amount')); - //$object->remise_absolue = price2num(GETPOST('remise_absolue'), 'MU'); - //$object->remise_percent = price2num(GETPOST('remise_percent'), '', 2); - $object->fk_incoterms = GETPOST('incoterm_id', 'int'); - $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); - $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); - $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); - - // Source facture - $object->fac_rec = $fac_recid; - $fac_rec = new FactureFournisseurRec($db); - $fac_rec->fetch($object->fac_rec); - $fac_rec->fetch_lines(); - $object->lines = $fac_rec->lines; - - $id = $object->create($user); // This include recopy of links from recurring invoice and recurring invoice lines - } - } elseif ($fac_recid <= 0 && (GETPOST('type') == FactureFournisseur::TYPE_STANDARD || GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT)) { - // Standard invoice or Deposit invoice, not from a Predefined template invoice - if (GETPOST('socid', 'int') < 1) { + $remain_to_pay = abs($facture_source->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits); + + $object->addline($langs->trans('invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 0, 0, 0, 1, 0, 0, '', '', 'TTC'); + } + } + } + } + + // Standard or deposit + if ($_POST['type'] == FactureFournisseur::TYPE_STANDARD || $_POST['type'] == FactureFournisseur::TYPE_DEPOSIT) + { + if (GETPOST('socid', 'int') < 1) + { @@ -1024 +828,2 @@ - if (empty($dateinvoice)) { + if ($datefacture == '') + { @@ -1029,8 +834,4 @@ - } elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (!getDolGlobalString('INVOICE_MAX_FUTURE_DELAY') ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) { - $error++; - setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors'); - $action = 'create'; - } - - if (!GETPOST('ref_supplier')) { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('RefSupplierBill')), null, 'errors'); + } + if (!GETPOST('ref_supplier')) + { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('RefSupplier')), null, 'errors'); @@ -1042,7 +843,2 @@ - if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED') && empty(GETPOST("subtype"))) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InvoiceSubtype")), null, 'errors'); - $action = 'create'; - } - - if (!$error) { + if (!$error) + { @@ -1051,23 +847,17 @@ - // Creation invoice - $object->socid = GETPOST('socid', 'int'); - $object->type = GETPOST('type', 'alphanohtml'); - $object->subtype = GETPOST('subtype', 'alphanohtml'); - $object->ref = GETPOST('ref', 'alphanohtml'); - $object->ref_supplier = GETPOST('ref_supplier', 'alphanohtml'); - $object->socid = GETPOST('socid', 'int'); - $object->libelle = GETPOST('label', 'alphanohtml'); // deprecated - $object->label = GETPOST('label', 'alphanohtml'); - $object->date = $dateinvoice; - $object->date_echeance = $datedue; - $object->note_public = GETPOST('note_public', 'restricthtml'); - $object->note_private = GETPOST('note_private', 'restricthtml'); - $object->cond_reglement_id = GETPOST('cond_reglement_id'); - $object->mode_reglement_id = GETPOST('mode_reglement_id'); - $object->fk_account = GETPOST('fk_account', 'int'); - $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0; - $object->fk_project = ($tmpproject > 0) ? $tmpproject : null; - $object->fk_incoterms = GETPOST('incoterm_id', 'int'); - $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); - $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); - $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); - $object->transport_mode_id = GETPOST('transport_mode_id'); + // Creation facture + $object->ref = $_POST['ref']; + $object->ref_supplier = $_POST['ref_supplier']; + $object->socid = $_POST['socid']; + $object->libelle = $_POST['label']; + $object->date = $datefacture; + $object->date_echeance = $datedue; + $object->note_public = GETPOST('note_public', 'none'); + $object->note_private = GETPOST('note_private', 'none'); + $object->cond_reglement_id = GETPOST('cond_reglement_id'); + $object->mode_reglement_id = GETPOST('mode_reglement_id'); + $object->fk_account = GETPOST('fk_account', 'int'); + $object->fk_project = ($tmpproject > 0) ? $tmpproject : null; + $object->fk_incoterms = GETPOST('incoterm_id', 'int'); + $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); + $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); + $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); @@ -1076,3 +866 @@ - if (empty($object->date_echeance)) { - $object->date_echeance = $object->calculate_date_lim_reglement(); - } + if (empty($object->date_echeance)) $object->date_echeance = $object->calculate_date_lim_reglement(); @@ -1083 +871,2 @@ - if (!$error && GETPOST('origin', 'alpha') && GETPOST('originid')) { + if (!$error && $_POST['origin'] && $_POST['originid']) + { @@ -1086 +875 @@ - /*if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'),$regs)) + /*if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs)) @@ -1097,2 +886 @@ - $element = 'comm/propal'; - $subelement = 'propal'; + $element = 'comm/propal'; $subelement = 'propal'; @@ -1104,4 +892,4 @@ - $element = 'fourn'; - $subelement = 'fournisseur.commande'; - } - if ($element == 'project') { + $element = 'fourn'; $subelement = 'fournisseur.commande'; + } + if ($element == 'project') + { @@ -1116,3 +904 @@ - if ($classname == 'Fournisseur.commande') { - $classname = 'CommandeFournisseur'; - } + if ($classname == 'Fournisseur.commande') $classname = 'CommandeFournisseur'; @@ -1123 +909,2 @@ - if (!empty($object->origin) && !empty($object->origin_id)) { + if (!empty($object->origin) && !empty($object->origin_id)) + { @@ -1128 +915,2 @@ - if ($object->origin == 'reception') { + if ($object->origin == 'reception') + { @@ -1131,2 +919,4 @@ - if (count($objectsrc->linkedObjectsIds['order_supplier']) > 0) { - foreach ($objectsrc->linkedObjectsIds['order_supplier'] as $key => $value) { + if (count($objectsrc->linkedObjectsIds['order_supplier']) > 0) + { + foreach ($objectsrc->linkedObjectsIds['order_supplier'] as $key => $value) + { @@ -1141 +931,2 @@ - if ($id > 0) { + if ($id > 0) + { @@ -1144,3 +935 @@ - if ($classname == 'Fournisseur.commande') { - $classname = 'CommandeFournisseur'; - } + if ($classname == 'Fournisseur.commande') $classname = 'CommandeFournisseur'; @@ -1150,140 +939,2 @@ - - // If deposit invoice - down payment with 1 line (fixed amount or percent) - $typeamount = GETPOST('typedeposit', 'alpha'); - if (GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT && in_array($typeamount, array('amount', 'variable'))) { - $valuedeposit = price2num(GETPOST('valuedeposit', 'alpha'), 'MU'); - - // Define the array $amountdeposit - $amountdeposit = array(); - if (getDolGlobalString('MAIN_DEPOSIT_MULTI_TVA')) { - if ($typeamount == 'amount') { - $amount = $valuedeposit; - } else { - $amount = $srcobject->total_ttc * ($valuedeposit / 100); - } - - $TTotalByTva = array(); - foreach ($srcobject->lines as &$line) { - if (!empty($line->special_code)) { - continue; - } - $TTotalByTva[$line->tva_tx] += $line->total_ttc; - } - - 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') { - $amountdeposit[0] = $valuedeposit; - } 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 ($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; - $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100; - } - } - - if ($totalamount == 0) { - $amountdeposit[0] = 0; - } - } else { - setEventMessages($srcobject->error, $srcobject->errors, 'errors'); - $error++; - } - } - - $amount_ttc_diff = $amountdeposit[0]; - } - - foreach ($amountdeposit as $tva => $amount) { - if (empty($amount)) { - continue; - } - - $arraylist = array( - 'amount' => 'FixAmount', - 'variable' => 'VarAmount' - ); - $descline = '(DEPOSIT)'; - //$descline.= ' - '.$langs->trans($arraylist[$typeamount]); - if ($typeamount == 'amount') { - $descline .= ' ('.price($valuedeposit, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).')'; - } elseif ($typeamount == 'variable') { - $descline .= ' ('.$valuedeposit.'%)'; - } - - $descline .= ' - '.$srcobject->ref; - $result = $object->addline( - $descline, - $amount, // subprice - $tva, // vat rate - 0, // localtax1_tx - 0, // localtax2_tx - 1, // quantity - (!getDolGlobalString('INVOICE_PRODUCTID_DEPOSIT') ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT), // fk_product - 0, // remise_percent - 0, // date_start - 0, // date_end - 0, - $lines[$i]->info_bits, // info_bits - 'HT', - 0, // product_type - 1, - 0, - 0, - null, - $object->origin, - 0, - '', - $lines[$i]->special_code, - 0, - 0 - //,$langs->trans('Deposit') //Deprecated - ); - } - - $diff = $object->total_ttc - $amount_ttc_diff; - - if (getDolGlobalString('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]->tva_tx, - $object->lines[0]->localtax1_tx, - $object->lines[0]->localtax2_tx, - $object->lines[0]->qty, - $object->lines[0]->fk_product, - 'HT', - $object->lines[0]->info_bits, - $object->lines[0]->product_type, - $object->lines[0]->remise_percent, - 0, - $object->lines[0]->date_start, - $object->lines[0]->date_end, - 0, - 0, - 0, - '', - 100 - ); - } - } elseif ($result > 0) { + if ($result > 0) + { @@ -1291 +942,2 @@ - if (empty($lines) && method_exists($srcobject, 'fetch_lines')) { + if (empty($lines) && method_exists($srcobject, 'fetch_lines')) + { @@ -1297,5 +949,2 @@ - for ($i = 0; $i < $num; $i++) { // TODO handle subprice < 0 - if (!in_array($lines[$i]->id, $selectedLines)) { - continue; // Skip unselected lines - } - + for ($i = 0; $i < $num; $i++) // TODO handle subprice < 0 + { @@ -1313,6 +962,2 @@ - if ($lines[$i]->date_debut_reel) { - $date_start = $lines[$i]->date_debut_reel; - } - if ($lines[$i]->date_start) { - $date_start = $lines[$i]->date_start; - } + if ($lines[$i]->date_debut_reel) $date_start = $lines[$i]->date_debut_reel; + if ($lines[$i]->date_start) $date_start = $lines[$i]->date_start; @@ -1320,6 +965,2 @@ - if ($lines[$i]->date_fin_reel) { - $date_end = $lines[$i]->date_fin_reel; - } - if ($lines[$i]->date_end) { - $date_end = $lines[$i]->date_end; - } + if ($lines[$i]->date_fin_reel) $date_end = $lines[$i]->date_fin_reel; + if ($lines[$i]->date_end) $date_end = $lines[$i]->date_end; @@ -1331 +972,2 @@ - if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { + if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) + { @@ -1334 +976,3 @@ - } else { + } + else + { @@ -1365 +1009,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -1373 +1018,3 @@ - } else { + } + else + { @@ -1376 +1023,3 @@ - } else { + } + else + { @@ -1379 +1028,3 @@ - } elseif (!$error) { + } + elseif (!$error) + { @@ -1381 +1032,2 @@ - if ($id < 0) { + if ($id < 0) + { @@ -1388 +1040,2 @@ - if ($error) { + if ($error) + { @@ -1395 +1048,3 @@ - } else { + } + else + { @@ -1398 +1053 @@ - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { @@ -1400,2 +1055,3 @@ - $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result < 0) { + $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result < 0) + { @@ -1410,2 +1066,5 @@ - } elseif ($action == 'updateline' && $usercancreate) { - // Edit line + } + + // Edit line + elseif ($action == 'updateline' && $user->rights->fournisseur->facture->creer) + { @@ -1414,3 +1073 @@ - if (! $object->fetch($id) > 0) { - dol_print_error($db); - } + $object->fetch($id); @@ -1419,5 +1076,5 @@ - $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); - $tva_tx = str_replace('*', '', $tva_tx); - - if (GETPOST('price_ht') != '' || GETPOST('multicurrency_subprice') != '') { - $up = price2num(GETPOST('price_ht'), '', 2); + $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); + + if (GETPOST('price_ht') != '') + { + $up = price2num(GETPOST('price_ht')); @@ -1425,2 +1082,4 @@ - } else { - $up = price2num(GETPOST('price_ttc'), '', 2); + } + else + { + $up = price2num(GETPOST('price_ttc')); @@ -1430 +1089,2 @@ - if (GETPOST('productid') > 0) { + if (GETPOST('productid') > 0) + { @@ -1432,2 +1092,4 @@ - if (getDolGlobalString('SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY')) { - if (GETPOST('productid') > 0 && $productsupplier->get_buyprice(0, price2num(GETPOST('qty')), GETPOST('productid', 'int'), 'restricthtml', GETPOST('socid', 'int')) < 0) { + if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) + { + if (GETPOST('productid') > 0 && $productsupplier->get_buyprice(0, price2num($_POST['qty']), GETPOST('productid'), 'none', GETPOST('socid', 'int')) < 0) + { @@ -1441,3 +1103 @@ - if (trim(GETPOST('product_desc', 'restricthtml')) != trim($label)) { - $label = GETPOST('product_desc', 'restricthtml'); - } + if (trim($_POST['product_desc']) != trim($label)) $label = $_POST['product_desc']; @@ -1446,3 +1106,5 @@ - } else { - $label = GETPOST('product_desc', 'restricthtml'); - $type = GETPOST("type") ? GETPOST("type") : 0; + } + else + { + $label = $_POST['product_desc']; + $type = $_POST["type"] ? $_POST["type"] : 0; @@ -1454,13 +1116,12 @@ - // Define info_bits - $info_bits = 0; - if (preg_match('/\*/', $tva_tx)) { - $info_bits |= 0x01; - } - - // Define vat_rate - $tva_tx = str_replace('*', '', $tva_tx); - $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty); - $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty); - - $remise_percent = price2num(GETPOST('remise_percent'), '', 2); - $pu_devise = price2num(GETPOST('multicurrency_subprice'), 'MU', 2); + // Define info_bits + $info_bits = 0; + if (preg_match('/\*/', $tva_tx)) + $info_bits |= 0x01; + + // Define vat_rate + $tva_tx = str_replace('*', '', $tva_tx); + $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty); + $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty); + + $remise_percent = GETPOST('remise_percent'); + $pu_ht_devise = GETPOST('multicurrency_subprice'); @@ -1478,25 +1139,6 @@ - $result = $object->updateline( - GETPOST('lineid', 'int'), - $label, - $up, - $tva_tx, - $localtax1_tx, - $localtax2_tx, - price2num(GETPOST('qty'), 'MS'), - GETPOST('productid', 'int'), - $price_base_type, - $info_bits, - $type, - $remise_percent, - 0, - $date_start, - $date_end, - $array_options, - GETPOST('units', 'alpha'), - $pu_devise, - GETPOST('fourn_ref', 'alpha') - ); - if ($result >= 0) { - unset($_POST['label']); - unset($_POST['fourn_ref']); - unset($_POST['date_starthour']); + $result = $object->updateline(GETPOST('lineid'), $label, $up, $tva_tx, $localtax1_tx, $localtax2_tx, GETPOST('qty'), GETPOST('productid'), $price_base_type, $info_bits, $type, $remise_percent, 0, $date_start, $date_end, $array_options, $_POST['units'], $pu_ht_devise, GETPOST('fourn_ref', 'alpha')); + if ($result >= 0) + { + unset($_POST['label']); + unset($_POST['fourn_ref']); + unset($_POST['date_starthour']); @@ -1514,2 +1155,0 @@ - unset($_POST['price_ttc']); - unset($_POST['price_ht']); @@ -1518 +1158,3 @@ - } else { + } + else + { @@ -1522,11 +1164,4 @@ - } elseif ($action == 'addline' && GETPOST('submitforalllines', 'aZ09') && GETPOST('vatforalllines', 'alpha') != '' && $usercancreate) { - // Define vat_rate - $vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0); - $vat_rate = str_replace('*', '', $vat_rate); - $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc); - $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc); - foreach ($object->lines as $line) { - $result = $object->updateline($line->id, $line->desc, $line->subprice, $vat_rate, $localtax1_rate, $localtax2_rate, $line->qty, $line->fk_product, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier, $line->rang); - } - } elseif ($action == 'addline' && $usercancreate) { - // Add a product line + } + + elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer) + { @@ -1536 +1171,2 @@ - if ($ret < 0) { + if ($ret < 0) + { @@ -1547 +1183 @@ - $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); + $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); @@ -1552 +1188,2 @@ - if ($prod_entry_mode == 'free') { + if ($prod_entry_mode == 'free') + { @@ -1554 +1191,5 @@ - } else { + $price_ht = GETPOST('price_ht'); + $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); + } + else + { @@ -1556,14 +1197,7 @@ - } - - $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); // Can be '1.2' or '1.2 (CODE)' - - $price_ht = price2num(GETPOST('price_ht'), 'MU', 2); - $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2); - $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2); - $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2); - $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS'); - - $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0); - if (empty($remise_percent)) { - $remise_percent = 0; - } + $price_ht = GETPOST('price_ht'); + $tva_tx = ''; + } + + $qty = GETPOST('qty'.$predef); + $remise_percent = GETPOST('remise_percent'.$predef); + $price_ht_devise = GETPOST('multicurrency_price_ht'); @@ -1582 +1216,2 @@ - if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0) { + if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0) + { @@ -1586 +1221,2 @@ - if ($prod_entry_mode == 'free' && !GETPOST('idprodfournprice') && GETPOST('type') < 0) { + if ($prod_entry_mode == 'free' && !GETPOST('idprodfournprice') && GETPOST('type') < 0) + { @@ -1590 +1226,2 @@ - if ($prod_entry_mode == 'free' && GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && $price_ht_devise === '') { // Unit price can be 0 but not '' + if ($prod_entry_mode == 'free' && GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && $price_ht_devise === '') // Unit price can be 0 but not '' + { @@ -1594 +1231,2 @@ - if ($prod_entry_mode == 'free' && !GETPOST('dp_desc')) { + if ($prod_entry_mode == 'free' && !GETPOST('dp_desc')) + { @@ -1598 +1236,2 @@ - if (!GETPOST('qty', 'alpha')) { // 0 is NOT allowed for invoices + if (!GETPOST('qty')) + { @@ -1603 +1242 @@ - if (!$error && isModEnabled('variants') && $prod_entry_mode != 'free') { + if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode != 'free') { @@ -1617 +1256,2 @@ - if ($prod_entry_mode != 'free' && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or '' + if ($prod_entry_mode != 'free' && empty($error)) // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or '' + { @@ -1621,3 +1261 @@ - if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') { - $idprod = -99; // Same behaviour than with combolist. When not select idprodfournprice is now -99 (to avoid conflict with next action that may return -1, -2, ...) - } + if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') $idprod = -99; // Same behaviour than with combolist. When not select idprodfournprice is now -99 (to avoid conflict with next action that may return -1, -2, ...) @@ -1626 +1264,2 @@ - if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) { + if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) + { @@ -1631 +1270,2 @@ - if (getDolGlobalString('SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) { + if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) + { @@ -1634 +1274,2 @@ - if ($productsupplier->fourn_socid != $socid) { // The price we found is for another supplier, so we clear supplier price + if ($productsupplier->fourn_socid != $socid) // The price we found is for another supplier, so we clear supplier price + { @@ -1637 +1278,3 @@ - } else { + } + else + { @@ -1641 +1284,3 @@ - } elseif (GETPOST('idprodfournprice', 'alpha') > 0) { + } + elseif (GETPOST('idprodfournprice', 'alpha') > 0) + { @@ -1648 +1293,2 @@ - if ($idprod > 0) { + if ($idprod > 0) + { @@ -1650,18 +1296 @@ - // Define output language - if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { - $outputlangs = $langs; - $newlang = ''; - if (empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang]["description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang]["description"] : $productsupplier->description; - } else { - $desc = $productsupplier->description; - } + @@ -1669,27 +1298,5 @@ - if (!empty($productsupplier->desc_supplier) && getDolGlobalString('PRODUIT_FOURN_TEXTS')) { - $desc = $productsupplier->desc_supplier; - } - - //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time - if (trim($product_desc) == trim($desc) && getDolGlobalString('PRODUIT_AUTOFILL_DESC')) { - $product_desc = ''; - } - if (!empty($product_desc) && getDolGlobalString('MAIN_NO_CONCAT_DESCRIPTION')) { - $desc = $product_desc; - } - if (!empty($product_desc) && trim($product_desc) != trim($desc)) { - $desc = dol_concatdesc($desc, $product_desc, '', getDolGlobalString('MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION')); - } - - $ref_supplier = $productsupplier->ref_supplier; - - // Get vat rate - if (!GETPOSTISSET('tva_tx')) { // If vat rate not provided from the form (the form has the priority) - $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha')); - $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha')); - } - if (empty($tva_tx) || empty($tva_npr)) { - $tva_npr = 0; - } - $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr); - $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr); + if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) { + $desc = $productsupplier->desc_supplier; + } else $desc = $productsupplier->description; + + if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); @@ -1698 +1305 @@ - if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') { + if ($price_ht != '' || $price_ht_devise != '') { @@ -1701,5 +1308 @@ - $pu_devise = price2num($price_ht_devise, 'CU'); - } elseif (GETPOST('price_ttc') != '' || GETPOST('multicurrency_price_ttc') != '') { - $price_base_type = 'TTC'; - $pu = price2num($price_ttc, 'MU'); - $pu_devise = price2num($price_ttc_devise, 'CU'); + $pu_ht_devise = price2num($price_ht_devise, 'MU'); @@ -1710 +1313 @@ - $pu_devise = 0; + $pu_ht_devise = 0; @@ -1713 +1316 @@ - $pu_devise = $productsupplier->fourn_multicurrency_unitprice; + $pu_ht_devise = $productsupplier->fourn_multicurrency_unitprice; @@ -1721,3 +1324 @@ - if (empty($tva_tx)) { - $tva_npr = 0; - } + if (empty($tva_tx)) $tva_npr = 0; @@ -1727,3 +1328 @@ - if (empty($pu)) { - $pu = 0; // If pu is '' or null, we force to have a numeric value - } + if (empty($pu)) $pu = 0; // If pu is '' or null, we force to have a numeric value @@ -1746 +1345 @@ - min($rank, count($object->lines) + 1), + -1, @@ -1751,2 +1350,2 @@ - $pu_devise, - GETPOST('fourn_ref', 'alpha'), + $pu_ht_devise, + $ref_supplier, @@ -1756 +1355,2 @@ - if ($idprod == -99 || $idprod == 0) { + if ($idprod == -99 || $idprod == 0) + { @@ -1762 +1362,2 @@ - if ($idprod == -1) { + if ($idprod == -1) + { @@ -1768 +1369,3 @@ - } elseif (empty($error)) { // $price_ht is already set + } + elseif (empty($error)) // $price_ht is already set + { @@ -1778,3 +1381 @@ - if (!preg_match('/\((.*)\)/', $tva_tx)) { - $tva_tx = price2num($tva_tx); // $txtva can have format '5,1' or '5.1' or '5.1(XXX)', we must clean only if '5,1' - } + $tva_tx = price2num($tva_tx); // When vat is text input field @@ -1786 +1387,2 @@ - if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') { + if ($price_ht !== '') + { @@ -1788 +1390,3 @@ - } else { + } + else + { @@ -1793,3 +1397,3 @@ - $pu_devise = price2num($price_ht_devise, 'CU'); - - $result = $object->addline($product_desc, $pu_ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit, 0, $pu_devise, $ref_supplier); + $pu_ht_devise = price2num($price_ht_devise, 'MU'); + + $result = $object->addline($product_desc, $pu_ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit, 0, $pu_ht_devise, $ref_supplier); @@ -1799 +1403,2 @@ - if (!$error && $result > 0) { + if (!$error && $result > 0) + { @@ -1803 +1408,2 @@ - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { @@ -1806,6 +1412,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; @@ -1816 +1418 @@ - $model = $object->model_pdf; + $model = $object->modelpdf; @@ -1820,3 +1422 @@ - if ($result < 0) { - dol_print_error($db, $result); - } + if ($result < 0) dol_print_error($db, $result); @@ -1857 +1457,3 @@ - } else { + } + else + { @@ -1863 +1465,4 @@ - } elseif ($action == 'classin' && $usercancreate) { + } + + elseif ($action == 'classin' && $user->rights->fournisseur->facture->creer) + { @@ -1866,2 +1471,6 @@ - } elseif ($action == 'confirm_edit' && $confirm == 'yes' && $usercancreate) { - // Set invoice to draft status + } + + + // Set invoice to draft status + elseif ($action == 'confirm_edit' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) + { @@ -1870,2 +1479,2 @@ - $totalpaid = $object->getSommePaiement(); - $resteapayer = $object->total_ttc - $totalpaid; + $totalpaye = $object->getSommePaiement(); + $resteapayer = $object->total_ttc - $totalpaye; @@ -1876,25 +1485,32 @@ - if (!$ventilExportCompta) { - // On verifie si aucun paiement n'a ete effectue - if ($resteapayer == price2num($object->total_ttc, 'MT', 1) && $object->statut == FactureFournisseur::STATUS_VALIDATED) { - $idwarehouse = GETPOST('idwarehouse'); - - $object->fetch_thirdparty(); - - $qualified_for_stock_change = 0; - if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { - $qualified_for_stock_change = $object->hasProductsOrServices(2); - } else { - $qualified_for_stock_change = $object->hasProductsOrServices(1); - } - - // Check parameters - if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) { - $langs->load("stocks"); - if (!$idwarehouse || $idwarehouse == -1) { - $error++; - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); - $action = ''; - } - } - - $object->setDraft($user, $idwarehouse); + if (!$ventilExportCompta) + { + // On verifie si aucun paiement n'a ete effectue + if ($resteapayer == price2num($object->total_ttc, 'MT', 1) && $object->statut == FactureFournisseur::STATUS_VALIDATED) + { + $idwarehouse = GETPOST('idwarehouse'); + + $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 (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) + { + $langs->load("stocks"); + if (!$idwarehouse || $idwarehouse == -1) + { + $error++; + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); + $action = ''; + } + } + + $object->setDraft($user, $idwarehouse); @@ -1903 +1519,2 @@ - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { @@ -1906,6 +1523,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; @@ -1916 +1529 @@ - $model = $object->model_pdf; + $model = $object->modelpdf; @@ -1920,3 +1533 @@ - if ($result < 0) { - dol_print_error($db, $result); - } + if ($result < 0) dol_print_error($db, $result); @@ -1928,2 +1539,5 @@ - } elseif ($action == 'reopen' && $usercancreate) { - // Set invoice to validated/unpaid status + } + + // Set invoice to validated/unpaid status + elseif ($action == 'reopen' && $user->rights->fournisseur->facture->creer) + { @@ -1932,3 +1546,5 @@ - || ($object->statut == FactureFournisseur::STATUS_ABANDONED && $object->close_code != 'replaced')) { - $result = $object->setUnpaid($user); - if ($result > 0) { + || ($object->statut == FactureFournisseur::STATUS_ABANDONED && $object->close_code != 'replaced')) + { + $result = $object->set_unpaid($user); + if ($result > 0) + { @@ -1937 +1553,3 @@ - } else { + } + else + { @@ -1950 +1568 @@ - $trackid = 'sinv'.$object->id; + $trackid = 'sin'.$object->id; @@ -1955 +1573 @@ - $permissiontoadd = $usercancreate; + $permissiontoadd = $user->rights->fournisseur->facture->creer; @@ -1959 +1577,2 @@ - if ($action == 'calculate') { + if ($action == 'calculate') + { @@ -1965 +1584,2 @@ - if ($result <= 0) { + if ($result <= 0) + { @@ -1970,2 +1590,3 @@ - if ($action == 'update_extras') { - $object->oldcopy = dol_clone($object, 2); + if ($action == 'update_extras') + { + $object->oldcopy = dol_clone($object); @@ -1974,6 +1595,5 @@ - $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); - if ($ret < 0) { - $error++; - } - - if (!$error) { + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); + if ($ret < 0) $error++; + + if (!$error) + { @@ -1981 +1601,2 @@ - if (!$error) { + if (!$error) + { @@ -1983 +1604,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -1989 +1611 @@ - if ($error) { + if ($error) @@ -1991,5 +1613,6 @@ - } - } - - if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB') && $usercancreate) { - if ($action == 'addcontact') { + } + + if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->facture->creer) + { + if ($action == 'addcontact') + { @@ -1998 +1621,2 @@ - if ($result > 0 && $id > 0) { + if ($result > 0 && $id > 0) + { @@ -2000,5 +1624,5 @@ - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); - } - - if ($result >= 0) { + $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); + } + + if ($result >= 0) + { @@ -2007,2 +1631,5 @@ - } else { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + } + else + { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { @@ -2011 +1638,3 @@ - } else { + } + else + { @@ -2015,5 +1644,11 @@ - } elseif ($action == 'swapstatut') { - // bascule du statut d'un contact - if ($object->fetch($id)) { - $result = $object->swapContactStatus(GETPOST('ligne', 'int')); - } else { + } + + // bascule du statut d'un contact + elseif ($action == 'swapstatut') + { + if ($object->fetch($id)) + { + $result = $object->swapContactStatus(GETPOST('ligne')); + } + else + { @@ -2022,2 +1657,5 @@ - } elseif ($action == 'deletecontact') { - // Efface un contact + } + + // Efface un contact + elseif ($action == 'deletecontact') + { @@ -2025,3 +1663,4 @@ - $result = $object->delete_contact(GETPOST("lineid", 'int')); - - if ($result >= 0) { + $result = $object->delete_contact($_GET["lineid"]); + + if ($result >= 0) + { @@ -2030 +1669,2 @@ - } else { + } + else { @@ -2046,3 +1686 @@ -if (isModEnabled('project')) { - $formproject = new FormProjets($db); -} +if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } @@ -2052,6 +1690,3 @@ -$title = $object->ref." - ".$langs->trans('Card'); -if ($action == 'create') { - $title = $langs->trans("NewSupplierInvoice"); -} -$help_url = 'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen'; -llxHeader('', $title, $help_url); +$title = $langs->trans('SupplierInvoice')." - ".$langs->trans('Card'); +$helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores"; +llxHeader('', $title, $helpurl); @@ -2060 +1695,2 @@ -if ($action == 'create') { +if ($action == 'create') +{ @@ -2063 +1699 @@ - print load_fiche_titre($langs->trans('NewSupplierInvoice'), '', 'supplier_invoice'); + print load_fiche_titre($langs->trans('NewBill'), '', 'supplier_invoice'); @@ -2070 +1706,2 @@ - if (GETPOST('socid', 'int') > 0) { + if (GETPOST('socid') > 0) + { @@ -2073,6 +1710,5 @@ - if (isModEnabled("multicurrency") && !empty($societe->multicurrency_code)) { - $currency_code = $societe->multicurrency_code; - } - } - - if (!empty($origin) && !empty($originid)) { + if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) $currency_code = $societe->multicurrency_code; + } + + if (!empty($origin) && !empty($originid)) + { @@ -2082 +1718,2 @@ - if ($element == 'project') { + if ($element == 'project') + { @@ -2092,2 +1729 @@ - $element = 'comm/propal'; - $subelement = 'propal'; + $element = 'comm/propal'; $subelement = 'propal'; @@ -2099,2 +1735 @@ - $element = 'fourn'; - $subelement = 'fournisseur.commande'; + $element = 'fourn'; $subelement = 'fournisseur.commande'; @@ -2105,3 +1740 @@ - if ($classname == 'Fournisseur.commande') { - $classname = 'CommandeFournisseur'; - } + if ($classname == 'Fournisseur.commande') $classname = 'CommandeFournisseur'; @@ -2113,0 +1747 @@ + @@ -2115,74 +1749,11 @@ - - $cond_reglement_id = 0; - $mode_reglement_id = 0; - $fk_account = 0; - //$remise_percent = 0; - //$remise_absolue = 0; - $transport_mode_id = 0; - - // set from object source - if (!empty($objectsrc->cond_reglement_id)) { - $cond_reglement_id = $objectsrc->cond_reglement_id; - } - if (!empty($objectsrc->mode_reglement_id)) { - $mode_reglement_id = $objectsrc->mode_reglement_id; - } - if (!empty($objectsrc->fk_account)) { - $fk_account = $objectsrc->fk_account; - } - if (!empty($objectsrc->transport_mode_id)) { - $transport_mode_id = $objectsrc->transport_mode_id; - } - - if (empty($cond_reglement_id) - || empty($mode_reglement_id) - || empty($fk_account) - || empty($transport_mode_id) - ) { - if ($origin == 'reception') { - // try to get from source of reception (supplier order) - if (!isset($objectsrc->supplier_order)) { - $objectsrc->fetch_origin(); - } - - if (!empty($objectsrc->commandeFournisseur)) { - $supplierOrder = $objectsrc->commandeFournisseur; - if (empty($cond_reglement_id) && !empty($supplierOrder->cond_reglement_id)) { - $cond_reglement_id = $supplierOrder->cond_reglement_id; - } - if (empty($mode_reglement_id) && !empty($supplierOrder->mode_reglement_id)) { - $mode_reglement_id = $supplierOrder->mode_reglement_id; - } - if (empty($fk_account) && !empty($supplierOrder->fk_account)) { - $fk_account = $supplierOrder->fk_account; - } - if (empty($transport_mode_id) && !empty($supplierOrder->transport_mode_id)) { - $transport_mode_id = $supplierOrder->transport_mode_id; - } - } - } - - // try to get from third-party of source object - if (!empty($soc)) { - if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) { - $cond_reglement_id = $soc->cond_reglement_supplier_id; - } - if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) { - $mode_reglement_id = $soc->mode_reglement_supplier_id; - } - if (empty($fk_account) && !empty($soc->fk_account)) { - $fk_account = $soc->fk_account; - } - if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) { - $transport_mode_id = $soc->transport_mode_id; - } - } - } - - if (isModEnabled("multicurrency")) { - if (!empty($objectsrc->multicurrency_code)) { - $currency_code = $objectsrc->multicurrency_code; - } - if (getDolGlobalString('MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) { - $currency_tx = $objectsrc->multicurrency_tx; - } + $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_supplier_id) ? $soc->cond_reglement_supplier_id : 0)); // TODO maybe add default value option + $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_supplier_id) ? $soc->mode_reglement_supplier_id : 0)); + $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0)); + $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_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 : ''; + + if (!empty($conf->multicurrency->enabled)) + { + if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code; + if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx; @@ -2192,3 +1763,3 @@ - $dateinvoice = ($datetmp == '' ? (!getDolGlobalString('MAIN_AUTOFILL_DATE') ? -1 : '') : $datetmp); - $datetmp = dol_mktime(12, 0, 0, GETPOST('echmonth', 'int'), GETPOST('echday', 'int'), GETPOST('echyear', 'int')); - $datedue = ($datetmp == '' ? -1 : $datetmp); + $dateinvoice = ($datetmp == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $datetmp); + $datetmp = dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear']); + $datedue = ($datetmp == '' ?-1 : $datetmp); @@ -2199,6 +1770,6 @@ - } else { - $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0; - $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0; - $vat_reverse_charge = (empty($societe) ? '' : $societe->vat_reverse_charge); - $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0; - $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0; + } + else + { + $cond_reglement_id = $societe->cond_reglement_supplier_id; + $mode_reglement_id = $societe->mode_reglement_supplier_id; + $fk_account = $societe->fk_account; @@ -2206,43 +1777,5 @@ - $dateinvoice = ($datetmp == '' ? (getDolGlobalInt('MAIN_AUTOFILL_DATE') ? '' : -1) : $datetmp); - $datetmp = dol_mktime(12, 0, 0, GETPOST('echmonth', 'int'), GETPOST('echday', 'int'), GETPOST('echyear', 'int')); - $datedue = ($datetmp == '' ? -1 : $datetmp); - - if (isModEnabled("multicurrency") && !empty($soc->multicurrency_code)) { - $currency_code = $soc->multicurrency_code; - } - } - - // when payment condition is empty (means not override by payment condition form a other object, like third-party), try to use default value - if (empty($cond_reglement_id)) { - $cond_reglement_id = GETPOST("cond_reglement_id"); - } - - // when payment mode is empty (means not override by payment condition form a other object, like third-party), try to use default value - if (empty($mode_reglement_id)) { - $mode_reglement_id = GETPOST("mode_reglement_id"); - } - - // If form was posted (but error returned), we must reuse the value posted in priority (standard Dolibarr behaviour) - if (!GETPOST('changecompany')) { - if (GETPOSTISSET('cond_reglement_id')) { - $cond_reglement_id = GETPOST('cond_reglement_id', 'int'); - } - if (GETPOSTISSET('mode_reglement_id')) { - $mode_reglement_id = GETPOST('mode_reglement_id', 'int'); - } - if (GETPOSTISSET('cond_reglement_id')) { - $fk_account = GETPOST('fk_account', 'int'); - } - } - - $note_public = $object->getDefaultCreateValueFor('note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && getDolGlobalString('FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_public : null)); - $note_private = $object->getDefaultCreateValueFor('note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && getDolGlobalString('FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM')) ? $objectsrc->note_private : null)); - - if ($origin == 'contrat') { - $langs->load("admin"); - $text = $langs->trans("ToCreateARecurringInvoice"); - $text .= ' '.$langs->trans("ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv("MenuFinancial"), $langs->transnoentitiesnoconv("SupplierBills"), $langs->transnoentitiesnoconv("ListOfTemplates")); - if (!getDolGlobalString('INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE')) { - $text .= ' '.$langs->trans("ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv('Module2300Name')); - } - print info_admin($text, 0, 0, 0, 'opacitymedium').'
'; + $dateinvoice = ($datetmp == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $datetmp); + $datetmp = dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear']); + $datedue = ($datetmp == '' ?-1 : $datetmp); + + if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code; @@ -2254,5 +1787 @@ - print ''; // will be set to 1 by javascript so we know post is done after a company change - - if (!empty($societe->id) && $societe->id > 0) { - print ''."\n"; - } + if ($societe->id > 0) print ''."\n"; @@ -2261,116 +1790,132 @@ - if (!empty($currency_tx)) { - print ''; - } - print ''; - - print dol_get_fiche_head(); - - // Call Hook tabContentCreateSupplierInvoice - $parameters = array(); - // Note that $action and $object may be modified by hook - $reshook = $hookmanager->executeHooks('tabContentCreateSupplierInvoice', $parameters, $object, $action); - if (empty($reshook)) { - print ''; - - // Ref - print ''; - - $exampletemplateinvoice = new FactureFournisseurRec($db); - $invoice_predefined = new FactureFournisseurRec($db); - if (empty($origin) && empty($originid) && $fac_recid > 0) { - $invoice_predefined->fetch($fac_recid); - } - - // Third party - print ''; - print ''; - - // Overwrite some values if creation of invoice is from a predefined invoice - if (empty($origin) && empty($originid) && $fac_recid > 0) { - $invoice_predefined->fetch($fac_recid); - - $dateinvoice = $invoice_predefined->date_when; // To use next gen date by default later - if (empty($projectid)) { - $projectid = $invoice_predefined->fk_project; - } - $cond_reglement_id = $invoice_predefined->cond_reglement_id; - $mode_reglement_id = $invoice_predefined->mode_reglement_id; - $fk_account = $invoice_predefined->fk_account; - $note_public = $invoice_predefined->note_public; - $note_private = $invoice_predefined->note_private; - - if (!empty($invoice_predefined->multicurrency_code)) { - $currency_code = $invoice_predefined->multicurrency_code; - } - if (!empty($invoice_predefined->multicurrency_tx)) { - $currency_tx = $invoice_predefined->multicurrency_tx; - } - - $sql = 'SELECT r.rowid, r.titre as title, r.total_ttc'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_rec as r'; - $sql .= ' WHERE r.fk_soc = '. (int) $invoice_predefined->socid; - - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - - if ($num > 0) { - print ''; - } - $db->free($resql); + if (!empty($currency_tx)) print ''; + + dol_fiche_head(); + + print '
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('Supplier').''; - - if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) { - $absolute_discount = $societe->getAvailableDiscounts('', '', 0, 1); - print $societe->getNomUrl(1, 'supplier'); - print ''; - } else { - $filter = '((s.fournisseur:=:1) AND (s.status:=:1))'; - print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company(empty($societe->id) ? 0 : $societe->id, 'socid', $filter, 'SelectThirdParty', 1, 0, null, 0, 'minwidth175 widthcentpercentminusxx maxwidth500'); - // reload page to retrieve supplier informations - if (!getDolGlobalString('RELOAD_PAGE_ON_SUPPLIER_CHANGE_DISABLED')) { - print ''; - } - if ($fac_recid <= 0) { - print ' '; - } - } - print '
'.$langs->trans('CreateFromRepeatableInvoice').''; - //print ''; - print ''; - // Option to reload page to retrieve customer informations. Note, this clear other input - if (!getDolGlobalString('RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED')) { - print ''; - } - print '
'; + + // Ref + print ''; + + // Third party + print ''; + print ''; + + // Ref supplier + print ''; + print ''; + + print ''; - print ''; - - print ''; + + if ($societe->id > 0) + { + // Discounts for third party + print ''; - } - - if (!empty($societe->id) && $societe->id > 0) { - // Discounts for third party - print ''; - } - - // Label - print ''; - - // Date invoice - print ''; + + // Date invoice + print ''; + + // Due date + print ''; + + // Payment term + print ''; + + // Payment mode + print ''; + + // Bank Account + print ''; + + // Multicurrency + if (!empty($conf->multicurrency->enabled)) + { + print ''; + print ''; + print ''; + print ''; + print ''; - - // Bank Account - if (isModEnabled("banque")) { - print ''; - } - - // Project - if (isModEnabled('project')) { - $formproject = new FormProjets($db); - - $langs->load('projects'); - print ''; - } - - // Incoterms - if (isModEnabled('incoterm')) { - print ''; - print ''; - print ''; - } - - // Vat reverse-charge by default - if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) { - require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; - print ''; - } - - // Multicurrency - if (isModEnabled("multicurrency")) { - print ''; - print ''; - print ''; - } - - // Help of substitution key - $htmltext = ''; - if ($fac_recid > 0) { - $dateexample = $dateinvoice; - if (empty($dateexample)) { - $dateexample = dol_now(); - } - $substitutionarray = array( - '__TOTAL_HT__' => $langs->trans("AmountHT").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ht).')', - '__TOTAL_TTC__' => $langs->trans("AmountTTC").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ttc).')', - '__INVOICE_PREVIOUS_MONTH__' => $langs->trans("PreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%m').')', - '__INVOICE_MONTH__' => $langs->trans("MonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%m').')', - '__INVOICE_NEXT_MONTH__' => $langs->trans("NextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%m').')', - '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans("TextPreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%B').')', - '__INVOICE_MONTH_TEXT__' => $langs->trans("TextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%B').')', - '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans("TextNextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%B').')', - '__INVOICE_PREVIOUS_YEAR__' => $langs->trans("PreviousYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'y'), '%Y').')', - '__INVOICE_YEAR__' => $langs->trans("YearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%Y').')', - '__INVOICE_NEXT_YEAR__' => $langs->trans("NextYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'y'), '%Y').')' - ); - - $htmltext = ''.$langs->trans("FollowingConstantsWillBeSubstituted").':
'; - foreach ($substitutionarray as $key => $val) { - $htmltext .= $key.' = '.$langs->trans($val).'
'; - } - $htmltext .= '
'; - } - - // Intracomm report - if (isModEnabled('intracommreport')) { - $langs->loadLangs(array("intracommreport")); - print ''."\n"; - print ''; - } - - if (empty($reshook)) { - print $object->showOptionals($extrafields, 'create'); - } - - // Public note - print ''; - print ''; - // print ''; - print ''; - - // Private note - print ''; - print ''; - // print ''; - print ''; - - - if (!empty($objectsrc) && is_object($objectsrc)) { - print "\n"; - print "\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''; - print ''; - - $txt = $langs->trans($classname); - if ($classname == 'CommandeFournisseur') { - $langs->load('orders'); - $txt = $langs->trans("SupplierOrder"); - } - print ''; - print ''; - print '"; - if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { //Localtax1 - print '"; - } - - if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { //Localtax2 - print '"; - } - print '"; - - if (isModEnabled("multicurrency")) { - print ''; - print '"; - print '"; - } - } - - // Other options - $parameters = array(); - $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - - - print "
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('Supplier').''; + + if ($societe->id > 0) + { + $absolute_discount = $societe->getAvailableDiscounts('', '', 0, 1); + print $societe->getNomUrl(1); + print ''; + } + else + { + print $form->select_company($societe->id, 'socid', 's.fournisseur=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); + // reload page to retrieve supplier informations + if (!empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE)) + { + print ''; + } + print ' '; + } + print '
'.$langs->trans('RefSupplier').'
'.$langs->trans('Type').''; + + print '
'."\n"; + + // Standard invoice + print '
'; + $tmp = ' '; + $desc = $form->textwithpicto($tmp.$langs->trans("InvoiceStandardAsk"), $langs->transnoentities("InvoiceStandardDesc"), 1, 'help', '', 0, 3); + print $desc; + print '
'; + + /* Not yet supported + if ((empty($origin)) || ((($origin == 'propal') || ($origin == 'commande')) && (! empty($originid)))) + { + // Deposit + if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) + { + print '
'; + $tmp=' '; + print ''; + + $desc = $form->textwithpicto($tmp.$langs->trans("InvoiceDeposit"), $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3); + print ''; + if (($origin == 'propal') || ($origin == 'commande')) + { + print ''; + print '
'; + print $desc; + print ''; + $arraylist = array('amount' => $langs->transnoentitiesnoconv('FixAmount', $langs->transnoentitiesnoconv('Deposit')), 'variable' => $langs->transnoentitiesnoconv('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit'))); + print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit'), 0, 0, 0, '', 1); + print '' . $langs->trans('Value') . ':'; + } + print '
'; + + print '
'; + } + } + */ + + /* Not yet supported for supplier + if ($societe->id > 0) + { + // Replacement + if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) + { + // Type invoice + $facids = $facturestatic->list_replacable_supplier_invoices($societe->id); + if ($facids < 0) { + dol_print_error($db, $facturestatic); + exit(); + } + $options = ""; + foreach ($facids as $facparam) + { + $options .= ''; + } + + print ''; + print '
'; + $tmp=' + jQuery(document).ready(function() { + jQuery("#fac_replacement").change(function() { + jQuery("#radio_replacement").prop("checked", true); + }); + }); + '; + $text = $tmp.$langs->trans("InvoiceReplacementAsk") . ' '; + $text .= '
'.$langs->trans('RefSupplierBill').'id) && $societe->id > 0) { - print ' autofocus'; - } - print '>
'.$langs->trans('Type').''; - - print '
'."\n"; - - // Standard invoice - print '
'; - $tmp = ' '; - $desc = $form->textwithpicto($tmp.'', $langs->transnoentities("InvoiceStandardDesc"), 1, 'help', '', 0, 3); - print $desc; - print '
'; - - if (empty($origin) || ($origin == 'order_supplier' && !empty($originid))) { - // Deposit - Down payment - if (!getDolGlobalString('INVOICE_DISABLE_DEPOSIT')) { - print '
'; - $tmp=' '; - print ''; - - $tmp = $tmp.''; - $desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3); - print ''; - print ''; - if ($origin == 'order_supplier') { - print ''; - print ''; - } - print '
'; - print $desc; - print ''; - $arraylist = array( - 'amount' => $langs->transnoentitiesnoconv('FixAmount', $langs->transnoentitiesnoconv('Deposit')), - 'variable' => $langs->transnoentitiesnoconv('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit')), - 'variablealllines' => $langs->transnoentitiesnoconv('VarAmountAllLines') - ); - print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit', 'aZ09'), 0, 0, 0, '', 1); - print ''; - print ''.$langs->trans("AmountOrPercent").''; - print '
'; - - print '
'; - } - } - - /* Not yet supported for supplier - if ($societe->id > 0) - { - // Replacement - if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) - { - // Type invoice - $facids = $facturestatic->list_replacable_supplier_invoices($societe->id); - if ($facids < 0) { - dol_print_error($db, $facturestatic->error, $facturestatic->errors); - exit(); - } - $options = ""; - foreach ($facids as $facparam) - { - $options .= ''; - } - - print ''; - print '
'; - $tmp=' - jQuery(document).ready(function() { - jQuery("#fac_replacement").change(function() { - jQuery("#radio_replacement").prop("checked", true); - }); - }); - '; - $text = $tmp.$langs->trans("InvoiceReplacementAsk") . ' '; - $text .= ''; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3); - print $desc; - print '
'; - } - } - else - { - print '
'; - $tmp=' '; - $text = $tmp.$langs->trans("InvoiceReplacement") . ' '; - $text.= '('.$langs->trans("YouMustCreateInvoiceFromSupplierThird").') '; + $text .= ''; + } + $text .= ''; @@ -2523,79 +1930,46 @@ - */ - - if (empty($origin)) { - if (!empty($societe->id) && $societe->id > 0) { - // Credit note - if (!getDolGlobalString('INVOICE_DISABLE_CREDIT_NOTE')) { - // Show link for credit note - $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id); - if ($facids < 0) { - dol_print_error($db, $facturestatic->error, $facturestatic->errors); - exit; - } - $optionsav = ""; - $newinvoice_static = new FactureFournisseur($db); - foreach ($facids as $key => $valarray) { - $newinvoice_static->id = $key; - $newinvoice_static->ref = $valarray ['ref']; - $newinvoice_static->statut = $valarray ['status']; - $newinvoice_static->type = $valarray ['type']; - $newinvoice_static->paye = $valarray ['paye']; - - $optionsav .= ''; - } - - print '
'; - $tmp = ' - jQuery(document).ready(function() { - if (! jQuery("#radio_creditnote").is(":checked")) - { - jQuery("#credit_note_options").hide(); - } - jQuery("#radio_creditnote").click(function() { - jQuery("#credit_note_options").show(); - }); - jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() { - jQuery("#credit_note_options").hide(); - }); - }); - '; - $text = $tmp.' '; - // $text.=''; - $text .= ''; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); - print $desc; - - print '
'; - print '    0 ? 'checked' : '').' /> '; - print '"; - print '
    0 ? 'checked' : '').' /> '; - print '"; - print '
'; - - print '
'; - } - } else { + } + else + { + print '
'; + $tmp=' '; + $text = $tmp.$langs->trans("InvoiceReplacement") . ' '; + $text.= '('.$langs->trans("YouMustCreateInvoiceFromSupplierThird").') '; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3); + print $desc; + print '
'; + } + */ + + if (empty($origin)) + { + if ($societe->id > 0) + { + // Credit note + if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) + { + // Show link for credit note + $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id); + if ($facids < 0) + { + dol_print_error($db, $facturestatic); + exit; + } + $optionsav = ""; + $newinvoice_static = new FactureFournisseur($db); + foreach ($facids as $key => $valarray) + { + $newinvoice_static->id = $key; + $newinvoice_static->ref = $valarray ['ref']; + $newinvoice_static->statut = $valarray ['status']; + $newinvoice_static->type = $valarray ['type']; + $newinvoice_static->paye = $valarray ['paye']; + + $optionsav .= ''; + } + @@ -2603,2 +1977,27 @@ - if (!getDolGlobalString('INVOICE_CREDIT_NOTE_STANDALONE')) { - $tmp = ' '; + $tmp = ' + jQuery(document).ready(function() { + if (! jQuery("#radio_creditnote").is(":checked")) + { + jQuery("#credit_note_options").hide(); + } + jQuery("#radio_creditnote").click(function() { + jQuery("#credit_note_options").show(); + }); + jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() { + jQuery("#credit_note_options").hide(); + }); + }); + '; + $text = $tmp.$langs->transnoentities("InvoiceAvoirAsk").' '; + // $text.=''; + $text .= ''; @@ -2612,5 +2010,36 @@ - print '
'."\n"; - } - } - - print '
'; + + print '
'; + print '    0 ? 'checked' : '').' /> '; + print '"; + print '
    0 ? 'checked' : '').' /> '; + print '"; + print '
'; + + print ''; + } + } + else + { + print '
'; + $tmp = ' '; + $text = $tmp.$langs->trans("InvoiceAvoir").' '; + $text .= '('.$langs->trans("YouMustCreateInvoiceFromSupplierThird").') '; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); + print $desc; + print '
'."\n"; + } + } + + print ''; + + print '
'.$langs->trans('Discounts').''; + + $thirdparty = $societe; + $discount_type = 1; + $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$societe->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')); + include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; @@ -2619,28 +2048,37 @@ - - - // Invoice Subtype - if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED')) { - print '
'.$langs->trans('InvoiceSubtype').''; - print $form->getSelectInvoiceSubtype(GETPOST('subtype'), 'subtype', 1, 0, ''); - print '
'.$langs->trans('Discounts').''; - - $thirdparty = $societe; - $discount_type = 1; - $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$societe->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')); - include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; - - print '
'.$langs->trans('Label').'
'.$langs->trans('DateInvoice').''; - print img_picto('', 'action', 'class="pictofixedwidth"'); - print $form->selectDate($dateinvoice, '', '', '', '', "add", 1, 1); + } + + // Label + print '
'.$langs->trans('Label').'
'.$langs->trans('DateInvoice').''; + print $form->selectDate($dateinvoice, '', '', '', '', "add", 1, 1); + print '
'.$langs->trans('DateMaxPayment').''; + print $form->selectDate($datedue, 'ech', '', '', '', "add", 1, 1); + print '
'.$langs->trans('PaymentConditionsShort').''; + $form->select_conditions_paiements(GETPOSTISSET('cond_reglement_id') ?GETPOST('cond_reglement_id', 'int') : $cond_reglement_id, 'cond_reglement_id'); + print '
'.$langs->trans('PaymentMode').''; + $form->select_types_paiements(GETPOSTISSET('mode_reglement_id') ?GETPOST('mode_reglement_id', 'int') : $mode_reglement_id, 'mode_reglement_id', 'DBIT'); + print '
'.$langs->trans('BankAccount').''; + $form->select_comptes((GETPOSTISSET('fk_account') ?GETPOST('fk_account', 'alpha') : $fk_account), 'fk_account', 0, '', 1); + print '
'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).''; + print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ?GETPOST('multicurrency_code', 'alpha') : $currency_code), 'multicurrency_code'); @@ -2648,6 +2086,10 @@ - - // Payment term - print '
'.$langs->trans('PaymentConditionsShort').''; - print img_picto('', 'payment', 'class="pictofixedwidth"'); - print $form->getSelectConditionsPaiements($cond_reglement_id, 'cond_reglement_id', -1, 1); - + } + + // Project + if (!empty($conf->projet->enabled)) + { + $formproject = new FormProjets($db); + + $langs->load('projects'); + print '
'.$langs->trans('Project').''; + $formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $societe->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth500'); @@ -2655,5 +2097,9 @@ - - // Due date - print '
'.$langs->trans('DateMaxPayment').''; - print img_picto('', 'action', 'class="pictofixedwidth"'); - print $form->selectDate($datedue, 'ech', '', '', '', "add", 1, 1); + } + + // Incoterms + if (!empty($conf->incoterm->enabled)) + { + print '
'; + print $form->select_incoterms(GETPOSTISSET('incoterm_id') ? GETPOST('incoterm_id', 'alphanohtml') : (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : ''), GETPOSTISSET('location_incoterms') ? GETPOST('location_incoterms', 'alphanohtml') : (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : '')); @@ -2661,186 +2107,103 @@ - - // Payment mode - print '
'.$langs->trans('PaymentMode').''; - print img_picto('', 'bank', 'class="pictofixedwidth"'); - $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id', 'DBIT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx'); - print '
'.$langs->trans('BankAccount').''; - // when bank account is empty (means not override by payment mode form a other object, like third-party), try to use default value - print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes($fk_account, 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1); - print '
'.$langs->trans('Project').''; - print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects((!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $societe->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx'); - print ' id) ? $soc->id : 0).($fac_recid > 0 ? '&fac_rec='.$fac_recid : '')).'">'; - print '
'; - print img_picto('', 'incoterm', 'class="pictofixedwidth"'); - print $form->select_incoterms(GETPOSTISSET('incoterm_id') ? GETPOST('incoterm_id', 'alphanohtml') : (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : ''), GETPOSTISSET('location_incoterms') ? GETPOST('location_incoterms', 'alphanohtml') : (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : '')); - print '
' . $langs->trans('VATReverseCharge') . ''; - // Try to propose to use VAT reverse charge even if the VAT reverse charge is not activated in the supplier card, if this corresponds to the context of use, the activation is proposed - if ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code != 'FR' && isInEEC($societe) && !empty($societe->tva_intra))) { - $vat_reverse_charge = 1; - } else { - $vat_reverse_charge = 0; - } - - print ''; - print '
'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).''; - print img_picto('', 'currency', 'class="pictofixedwidth"'); - $used_currency_code = $currency_code; - if (!GETPOST('changecompany')) { - $used_currency_code = GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code', 'alpha') : $currency_code; - } - print $form->selectMultiCurrency($used_currency_code, 'multicurrency_code'); - print '
'.$langs->trans('IntracommReportTransportMode').''; - $form->selectTransportMode(GETPOSTISSET('transport_mode_id') ? GETPOST('transport_mode_id') : $transport_mode_id, 'transport_mode_id'); - print '
'.$langs->trans('NotePublic').''; - $doleditor = new DolEditor('note_public', (GETPOSTISSET('note_public') ? GETPOST('note_public', 'restricthtml') : $note_public), '', 80, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%'); - print $doleditor->Create(1); - print '
'.$langs->trans('NotePrivate').''; - $doleditor = new DolEditor('note_private', (GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : $note_private), '', 80, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%'); - print $doleditor->Create(1); - print '
'.$txt.''.$objectsrc->getNomUrl(1); - // We check if Origin document (id and type is known) has already at least one invoice attached to it - $objectsrc->fetchObjectLinked($originid, $origin, '', 'invoice_supplier'); - - $invoice_supplier = $objectsrc->linkedObjects['invoice_supplier']; - - // count function need a array as argument (Note: the array must implement Countable too) - if (is_array($invoice_supplier)) { - $cntinvoice = count($invoice_supplier); - - if ($cntinvoice >= 1) { - setEventMessages('WarningBillExist', null, 'warnings'); - echo ' ('.$langs->trans('LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).')'; - } - } - - print '
'.$langs->trans('AmountHT').''.price($objectsrc->total_ht).'
'.$langs->trans('AmountVAT').''.price($objectsrc->total_tva)."
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($objectsrc->total_localtax1)."
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($objectsrc->total_localtax2)."
'.$langs->trans('AmountTTC').''.price($objectsrc->total_ttc)."
'.$langs->trans('MulticurrencyAmountHT').''.price($objectsrc->multicurrency_total_ht).'
'.$langs->trans('MulticurrencyAmountVAT').''.price($objectsrc->multicurrency_total_tva)."
'.$langs->trans('MulticurrencyAmountTTC').''.price($objectsrc->multicurrency_total_ttc)."
\n"; - } - - print dol_get_fiche_end(); - - print $form->buttonsSaveCancel("CreateDraft"); + } + + // Public note + print ''.$langs->trans('NotePublic').''; + print ''; + $note_public = $object->getDefaultCreateValueFor('note_public'); + if (empty($note_public))$note_public = $objectsrc->note_public; + $doleditor = new DolEditor('note_public', (GETPOSTISSET('note_public') ?GETPOST('note_public', 'none') : $note_public), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); + print $doleditor->Create(1); + print ''; + // print ''; + print ''; + + // Private note + print ''.$langs->trans('NotePrivate').''; + print ''; + $note_private = $object->getDefaultCreateValueFor('note_private'); + if (empty($note_private))$note_private = $objectsrc->note_private; + + $doleditor = new DolEditor('note_private', (GETPOSTISSET('note_private') ?GETPOST('note_private', 'none') : $note_private), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); + print $doleditor->Create(1); + print ''; + // print ''; + print ''; + + if (empty($reshook)) + { + print $object->showOptionals($extrafields, 'edit'); + } + + if (is_object($objectsrc)) + { + print "\n"; + print "\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''; + print ''; + + $txt = $langs->trans($classname); + if ($classname == 'CommandeFournisseur') { + $langs->load('orders'); + $txt = $langs->trans("SupplierOrder"); + } + print ''.$txt.''.$objectsrc->getNomUrl(1); + // We check if Origin document (id and type is known) has already at least one invoice attached to it + $objectsrc->fetchObjectLinked($originid, $origin, '', 'invoice_supplier'); + + $invoice_supplier = $objectsrc->linkedObjects['invoice_supplier']; + + // count function need a array as argument (Note: the array must implement Countable too) + if (is_array($invoice_supplier)) + { + $cntinvoice = count($invoice_supplier); + + if ($cntinvoice >= 1) + { + setEventMessages('WarningBillExist', null, 'warnings'); + echo ' ('.$langs->trans('LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).')'; + } + } + + echo ''; + print ''.$langs->trans('AmountHT').''.price($objectsrc->total_ht).''; + print ''.$langs->trans('AmountVAT').''.price($objectsrc->total_tva).""; + if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) //Localtax1 + { + print ''.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($objectsrc->total_localtax1).""; + } + + if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) //Localtax2 + { + print ''.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($objectsrc->total_localtax2).""; + } + print ''.$langs->trans('AmountTTC').''.price($objectsrc->total_ttc).""; + + if (!empty($conf->multicurrency->enabled)) + { + print ''.$langs->trans('MulticurrencyAmountHT').''.price($objectsrc->multicurrency_total_ht).''; + print ''.$langs->trans('MulticurrencyAmountVAT').''.price($objectsrc->multicurrency_total_tva).""; + print ''.$langs->trans('MulticurrencyAmountTTC').''.price($objectsrc->multicurrency_total_ttc).""; + } + } + + // Other options + $parameters = array(); + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + // Bouton "Create Draft" + print "\n"; + + dol_fiche_end(); + + print '
'; + print ''; + print '     '; + print ''; + print '
'; + + print "\n"; + @@ -2849 +2212,2 @@ - if (!empty($objectsrc) && is_object($objectsrc)) { + if (is_object($objectsrc)) + { @@ -2855 +2218,0 @@ - print '
'; @@ -2858 +2221 @@ - $objectsrc->printOriginLinesList('', $selectedLines); + $objectsrc->printOriginLinesList(); @@ -2861,9 +2224,12 @@ - print '
'; - } - - print "\n"; -} else { - if ($id > 0 || !empty($ref)) { - // - // View or edit mode - // + } +} +else +{ + if ($id > 0 || !empty($ref)) + { + /* *************************************************************************** */ + /* */ + /* Fiche en mode visu ou edition */ + /* */ + /* *************************************************************************** */ + @@ -2874,9 +2240 @@ - $result = $object->fetch($id, $ref); - if ($result <= 0) { - $langs->load("errors"); - print $langs->trans("ErrorRecordNotFound"); - llxFooter(); - $db->close(); - exit; - } - + $object->fetch($id, $ref); @@ -2884,8 +2242,7 @@ - if ($result < 0) { - dol_print_error($db, $object->error, $object->errors); - exit; - } - - $societe = $object->thirdparty; - - $totalpaid = $object->getSommePaiement(); + if ($result < 0) dol_print_error($db); + + $societe = new Fournisseur($db); + $result = $societe->fetch($object->socid); + if ($result < 0) dol_print_error($db); + + $totalpaye = $object->getSommePaiement(); @@ -2894 +2251 @@ - // print "totalpaid=".$totalpaid." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits." + // print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits." @@ -2899 +2256 @@ - // $resteapayer=bcadd($object->total_ttc,$totalpaid,$conf->global->MAIN_MAX_DECIMALS_TOT); + // $resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT); @@ -2901,18 +2258,4 @@ - $resteapayer = price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT'); - - // Multicurrency - $multicurrency_resteapayer = 0; - if (isModEnabled("multicurrency")) { - $multicurrency_totalpaid = $object->getSommePaiement(1); - $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1); - $multicurrency_totaldeposits = $object->getSumDepositsUsed(1); - $multicurrency_resteapayer = price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits, 'MT'); - // Code to fix case of corrupted data - // TODO We should not need this. Also data comes from not reliable value of $object->multicurrency_total_ttc that may be wrong if it was - // calculated by summing lines that were in a currency for some of them and into another for others (lines from discount/down payment into another currency for example) - if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) { - $resteapayer = price2num($multicurrency_resteapayer / $object->multicurrency_tx, 'MT'); - } - } - - if ($object->paye) { + $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); + + if ($object->paye) + { @@ -2923 +2266 @@ - if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) { // Never use this + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { // Never use this @@ -2937,4 +2280,2 @@ - * View card - */ - $objectidnext = $object->getIdReplacingInvoice(); - + * View card + */ @@ -2944 +2285 @@ - print dol_get_fiche_head($head, 'card', $titre, -1, 'supplier_invoice', 0, '', '', 0, '', 1); + dol_fiche_head($head, 'card', $titre, -1, 'bill'); @@ -2950,8 +2291,3 @@ - $type_fac = ''; - if ($object->type == FactureFournisseur::TYPE_STANDARD) { - $type_fac = 'ExcessPaid'; - } elseif ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) { - $type_fac = 'CreditNote'; - } elseif ($object->type == FactureFournisseur::TYPE_DEPOSIT) { - $type_fac = 'Deposit'; - } + if ($object->type == FactureFournisseur::TYPE_STANDARD) $type_fac = 'ExcessPaid'; + elseif ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) $type_fac = 'CreditNote'; + elseif ($object->type == FactureFournisseur::TYPE_DEPOSIT) $type_fac = 'Deposit'; @@ -2964 +2300,2 @@ - if ($action == 'clone') { + if ($action == 'clone') + { @@ -2967,2 +2304,2 @@ - array('type' => 'text', 'name' => 'newsupplierref', 'label' => $langs->trans("RefSupplierBill"), 'value' => $langs->trans("CopyOf").' '.$object->ref_supplier), - array('type' => 'date', 'name' => 'newdate', 'label' => $langs->trans("Date"), 'value' => dol_now()) + array('type' => 'text', 'name' => 'newsupplierref', 'label' => $langs->trans("RefSupplier"), 'value' => $langs->trans("CopyOf").' '.$object->ref_supplier), + array('type' => 'date', 'name' => 'newdate', 'label' => $langs->trans("Date"), 'value' => dol_now()) @@ -2974,5 +2311,8 @@ - // Confirmation of validation - if ($action == 'valid') { - // We check if number is temporary number - if (preg_match('/^[\(]?PROV/i', $object->ref) || empty($object->ref)) { - // empty should not happened, but when it occurs, the test save life + // Confirmation de la validation + if ($action == 'valid') + { + // on verifie si l'objet est en numerotation provisoire + $objectref = substr($object->ref, 1, 4); + if ($objectref == 'PROV') + { + $savdate = $object->date; @@ -2980 +2320,3 @@ - } else { + } + else + { @@ -2984,45 +2326,8 @@ - if ($numref < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $action = ''; - } else { - $text = $langs->trans('ConfirmValidateBill', $numref); - /*if (isModEnabled('notification')) - { - require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; - $notify=new Notify($db); - $text.='
'; - $text.=$notify->confirmMessage('BILL_SUPPLIER_VALIDATE',$object->socid, $object); - }*/ - $formquestion = array(); - - $qualified_for_stock_change = 0; - if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { - $qualified_for_stock_change = $object->hasProductsOrServices(2); - } else { - $qualified_for_stock_change = $object->hasProductsOrServices(1); - } - - if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) { - $langs->load("stocks"); - require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; - $formproduct = new FormProduct($db); - $warehouse = new Entrepot($db); - $warehouse_array = $warehouse->list_array(); - if (count($warehouse_array) == 1) { - $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans("WarehouseForStockIncrease", current($warehouse_array)); - $value = ''; - } else { - $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease"); - $value = $formproduct->selectWarehouses(GETPOST('idwarehouse') ? GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1); - } - $formquestion = array( - array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $value) - ); - } - - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, 1, 1); - } - } - - // Confirmation edit (back to draft) - if ($action == 'edit') { + $text = $langs->trans('ConfirmValidateBill', $numref); + /*if (! empty($conf->notification->enabled)) + { + require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; + $notify=new Notify($db); + $text.='
'; + $text.=$notify->confirmMessage('BILL_SUPPLIER_VALIDATE',$object->socid, $object); + }*/ @@ -3032 +2337,2 @@ - if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) + { @@ -3034 +2340,3 @@ - } else { + } + else + { @@ -3037,18 +2345,56 @@ - if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) { - $langs->load("stocks"); - require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; - $formproduct = new FormProduct($db); - $warehouse = new Entrepot($db); - $warehouse_array = $warehouse->list_array(); - if (count($warehouse_array) == 1) { - $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans("WarehouseForStockDecrease", current($warehouse_array)); - $value = ''; - } else { - $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockIncrease") : $langs->trans("SelectWarehouseForStockDecrease"); - $value = $formproduct->selectWarehouses(GETPOST('idwarehouse') ? GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1); - } - $formquestion = array( - array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $value) - ); - } - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnvalidateBill'), $langs->trans('ConfirmUnvalidateBill', $object->ref), 'confirm_edit', $formquestion, 1, 1); + + if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) + { + $langs->load("stocks"); + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; + $formproduct = new FormProduct($db); + $warehouse = new Entrepot($db); + $warehouse_array = $warehouse->list_array(); + if (count($warehouse_array) == 1) { + $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans("WarehouseForStockIncrease", current($warehouse_array)); + $value = ''; + } else { + $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease"); + $value = $formproduct->selectWarehouses(GETPOST('idwarehouse') ?GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1); + } + $formquestion = array( + array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $value) + ); + } + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, 1, 1); + } + + // Confirmation edit (back to draft) + if ($action == 'edit') + { + $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 (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) + { + $langs->load("stocks"); + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; + $formproduct = new FormProduct($db); + $warehouse = new Entrepot($db); + $warehouse_array = $warehouse->list_array(); + if (count($warehouse_array) == 1) { + $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans("WarehouseForStockDecrease", current($warehouse_array)); + $value = ''; + } else { + $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockIncrease") : $langs->trans("SelectWarehouseForStockDecrease"); + $value = $formproduct->selectWarehouses(GETPOST('idwarehouse') ?GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1); + } + $formquestion = array( + array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $value) + ); + } + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnvalidateBill'), $langs->trans('ConfirmUnvalidateBill', $object->ref), 'confirm_edit', $formquestion, 1, 1); @@ -3058 +2404,2 @@ - if ($action == 'paid' && ($resteapayer <= 0 || (getDolGlobalString('SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $resteapayer == $object->total_ttc))) { + if ($action == 'paid') + { @@ -3062,58 +2408,0 @@ - if ($action == 'paid' && $resteapayer > 0 && (!getDolGlobalString('SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $resteapayer != $object->total_ttc)) { - $close = array(); - // Code - $i = 0; - $close[$i]['code'] = 'discount_vat'; // escompte - $i++; - $close[$i]['code'] = 'badsupplier'; - $i++; - $close[$i]['code'] = 'other'; - $i++; - // Help - $i = 0; - $close[$i]['label'] = $langs->trans("HelpEscompte").'

'.$langs->trans("ConfirmClassifyPaidPartiallyReasonDiscountVatDesc"); - $i++; - $close[$i]['label'] = $langs->trans("ConfirmClassifyPaidPartiallyReasonBadSupplierDesc"); - $i++; - $close[$i]['label'] = $langs->trans("Other"); - $i++; - // Text - $i = 0; - $close[$i]['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans("Currency".$conf->currency)), $close[$i]['label'], 1); - $i++; - $close[$i]['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans("Currency".$conf->currency)), $close[$i]['label'], 1); - $i++; - $close[$i]['reason'] = $form->textwithpicto($langs->transnoentities("Other"), $close[$i]['label'], 1); - $i++; - // arrayreasons[code]=reason - foreach ($close as $key => $val) { - $arrayreasons[$close[$key]['code']] = $close[$key]['reason']; - } - - // Create a form table - $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' => '', 'morecss' => 'minwidth300')); - // Incomplete payment. We ask if the reason is discount or other - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidPartially', $object->ref), 'confirm_paid_partially', $formquestion, "yes", 1, 310); - } - - // Confirmation of the abandoned classification - if ($action == 'canceled') { - // Code - $close[1]['code'] = 'badsupplier'; - $close[2]['code'] = 'abandon'; - // Help - $close[1]['label'] = $langs->trans("ConfirmClassifyPaidPartiallyReasonBadSupplierDesc"); - $close[2]['label'] = $langs->trans("ConfirmClassifyAbandonReasonOtherDesc"); - // Text - $close[1]['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadSupplier", $object->ref), $close[1]['label'], 1); - $close[2]['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyAbandonReasonOther"), $close[2]['label'], 1); - // arrayreasons - $arrayreasons[$close[1]['code']] = $close[1]['reason']; - $arrayreasons[$close[2]['code']] = $close[2]['reason']; - - // Create a form table - $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' => '', 'morecss' => 'minwidth300')); - - $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('CancelBill'), $langs->trans('ConfirmCancelBill', $object->ref), 'confirm_canceled', $formquestion, "yes", 1, 250); - } - @@ -3121,50 +2410,6 @@ - if ($action == 'delete') { - $formquestion = array(); - - $qualified_for_stock_change = 0; - if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { - $qualified_for_stock_change = $object->hasProductsOrServices(2); - } else { - $qualified_for_stock_change = $object->hasProductsOrServices(1); - } - - if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') && $qualified_for_stock_change) { - $langs->load("stocks"); - require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; - $formproduct = new FormProduct($db); - $warehouse = new Entrepot($db); - $warehouse_array = $warehouse->list_array(); - - $selectwarehouse = ''; - - $selectyesno = array(0 => $langs->trans('No'), 1 => $langs->trans('Yes')); - - print ''; - - $formquestion = array( - array('type' => 'select', 'name' => 'revertstock', 'label' => $langs->trans("RevertProductsToStock"), 'select_show_empty' => 0, 'values' => $selectyesno), - array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $selectwarehouse, 'tdclass' => 'questionrevertstock hidden') - ); - } - - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', $formquestion, 1, 1); - } - if ($action == 'deletepayment') { + if ($action == 'delete') + { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1); + } + if ($action == 'deletepaiement') + { @@ -3175,2 +2420,3 @@ - // Confirmation to delete line - if ($action == 'ask_deleteline') { + // Confirmation to delete line + if ($action == 'ask_deleteline') + { @@ -3180 +2426,2 @@ - if (!$formconfirm) { + if (!$formconfirm) + { @@ -3183,5 +2430,2 @@ - if (empty($reshook)) { - $formconfirm .= $hookmanager->resPrint; - } elseif ($reshook > 0) { - $formconfirm = $hookmanager->resPrint; - } + if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; + elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; @@ -3194,22 +2438,192 @@ - // Supplier invoice card - $linkback = ''.$langs->trans("BackToList").''; - - $morehtmlref = '
'; - // Ref supplier - $morehtmlref .= $form->editfieldkey("RefSupplierBill", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("RefSupplierBill", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, 'string', '', null, null, '', 1); - // Thirdparty - $morehtmlref .= '
'.$object->thirdparty->getNomUrl(1, 'supplier'); - if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) { - $morehtmlref .= ' '; - } - // Project - if (isModEnabled('project')) { - $langs->load("projects"); - $morehtmlref .= '
'; - if ($permissiontoadd) { - $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); - if ($action != 'classify') { - $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; - } - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); + // Supplier invoice card + $linkback = ''.$langs->trans("BackToList").''; + + $morehtmlref = '
'; + // Ref supplier + $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->facture->creer, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->facture->creer, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); + if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' ('.$langs->trans("OtherBills").')'; + // Project + if (!empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref .= '
'.$langs->trans('Project').' '; + if ($user->rights->fournisseur->facture->creer) + { + if ($action != 'classify') { + $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; + } + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref .= ''; + $morehtmlref .= '
'; + } else { + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (!empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref .= ''; + $morehtmlref .= $proj->ref; + $morehtmlref .= ''; + } else { + $morehtmlref .= ''; + } + } + } + $morehtmlref .= '
'; + + $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + + print '
'; + print '
'; + print '
'; + + print ''; + + // Type + print ''; + + + // Relative and absolute discounts + print ''; + + // Label + print ''; + print ''; + print ''; + print ''; + + $form_permission = ($object->statut < FactureFournisseur::STATUS_CLOSED) && $user->rights->fournisseur->facture->creer && ($object->getSommePaiement() <= 0); + + // Date + print ''; + + // Default terms of the settlement + $langs->load('bills'); + print '"; + print ''; + + // Due date + print ''; + + // Mode of payment + $langs->load('bills'); + print ''; + + // Multicurrency + if (!empty($conf->multicurrency->enabled)) + { + // Multicurrency code + print ''; + print ''; + print ''; + if (!empty($conf->banque->enabled)) + { + $bankaccountstatic->id = $objp->baid; + $bankaccountstatic->ref = $objp->baref; + $bankaccountstatic->label = $objp->baref; + $bankaccountstatic->number = $objp->banumber; + + if (!empty($conf->accounting->enabled)) { + $bankaccountstatic->account_number = $objp->account_number; + + $accountingjournal = new AccountingJournal($db); + $accountingjournal->fetch($objp->fk_accountancy_journal); + $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1); @@ -3423,9 +2852,86 @@ - $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code); - } else { - $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); - if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { - print '
        '; - print ''.$langs->trans("ActualizeCurrency").''; - print '
'; - } - } + + print ''; + } + print ''; + print ''; + print ''; + $totalpaye += $objp->amount; + $i++; + } + } + else + { + print ''; + } + + /* + if ($object->paye == 0) + { + print ''; + print ''; + + $resteapayer = $object->total_ttc - $totalpaye; + + print ''; + print ''; + } + */ + + $db->free($result); + } + else + { + dol_print_error($db); + } + + if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE) + { + // Total already paid + print ''; + + //$resteapayer = $object->total_ttc - $totalpaye; + $resteapayeraffiche = $resteapayer; + + $cssforamountpaymentcomplete = 'amountpaymentcomplete'; + + // Loop on each credit note or deposit amount applied + $creditnoteamount = 0; + $depositamount = 0; + + + $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; + $sql .= " re.description, re.fk_invoice_supplier_source"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re"; + $sql .= " WHERE fk_invoice_supplier = ".$object->id; + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + $invoice = new FactureFournisseur($db); + while ($i < $num) { + $obj = $db->fetch_object($resql); + $invoice->fetch($obj->fk_invoice_supplier_source); + print ''; + print ''; + print '"; - print ''; - } - - // Vat reverse-charge by default - if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) { - print ''; - } - - // Incoterms - if (isModEnabled('incoterm')) { - print ''; - print ''; - } - - // Intracomm report - if (isModEnabled('intracommreport')) { - $langs->loadLangs(array("intracommreport")); - print ''."\n"; - print ''; - print ''; - } - - // Other attributes - $cols = 2; - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; - - print '
'.$langs->trans('Type').''; + print $object->getLibType(); + if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) + { + $facreplaced = new FactureFournisseur($db); + $facreplaced->fetch($object->fk_facture_source); + print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')'; + } + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) + { + $facusing = new FactureFournisseur($db); + $facusing->fetch($object->fk_facture_source); + print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')'; + } + + $facidavoir = $object->getListIdAvoirFromInvoice(); + if (count($facidavoir) > 0) + { + print ' ('.$langs->transnoentities("InvoiceHasAvoir"); + $i = 0; + foreach ($facidavoir as $id) + { + if ($i == 0) print ' '; + else print ','; + $facavoir = new FactureFournisseur($db); + $facavoir->fetch($id); + print $facavoir->getNomUrl(1); + } + print ')'; + } + if (isset($facidnext) && $facidnext > 0) + { + $facthatreplace = new FactureFournisseur($db); + $facthatreplace->fetch($facidnext); + print ' ('.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)).')'; + } + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_DEPOSIT) { + $discount = new DiscountAbsolute($db); + $result = $discount->fetch(0, 0, $object->id); + if ($result > 0) { + print '. '.$langs->trans("CreditNoteConvertedIntoDiscount", $object->getLibType(1), $discount->getNomUrl(1, 'discount')).'
'; + } + } + print '
'.$langs->trans('Discounts'); + print ''; + + $thirdparty = $societe; + $discount_type = 1; + $backtopage = urlencode($_SERVER["PHP_SELF"].'?facid='.$object->id); + include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; + + print '
'.$form->editfieldkey("Label", 'label', $object->label, $object, ($user->rights->fournisseur->facture->creer)).''.$form->editfieldval("Label", 'label', $object->label, $object, ($user->rights->fournisseur->facture->creer)).'
'.$form->editfieldkey("DateInvoice", 'datef', $object->datep, $object, $form_permission, 'datepicker').''; + print $form->editfieldval("Date", 'datef', $object->datep, $object, $form_permission, 'datepicker'); + print '
'; + print ''; + } + print '
'; + print $langs->trans('PaymentConditions'); + print ''; + if ($action != 'editconditions' && $user->rights->fournisseur->facture->creer) { + print 'id.'">'.img_edit($langs->trans('SetConditions'), 1).'
'; + print '
'; + if ($action == 'editconditions') + { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id'); + } + else + { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none'); + } + print "
'.$form->editfieldkey("DateMaxPayment", 'date_lim_reglement', $object->date_echeance, $object, $form_permission, 'datepicker').''; + print $form->editfieldval("DateMaxPayment", 'date_lim_reglement', $object->date_echeance, $object, $form_permission, 'datepicker'); + if ($action != 'editdate_lim_reglement' && $object->hasDelay()) { + print img_warning($langs->trans('Late')); + } + print '
'; + print ''; + if ($action != 'editmode' && $user->rights->fournisseur->facture->creer) { + print ''; + } + print '
'; + print $langs->trans('PaymentMode'); + print 'id.'">'.img_edit($langs->trans('SetMode'), 1).'
'; + print '
'; + if ($action == 'editmode') + { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'DBIT', 1, 1); + } + else + { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none'); + } + print '
'; + print ''; + if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) + print ''; + print '
'; + print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'
'; + print '
'; + if ($action == 'editmulticurrencycode') { + $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code'); @@ -3217,92 +2631 @@ - if (!empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref .= $proj->getNomUrl(1); - if ($proj->title) { - $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; - } - } - } - } - $morehtmlref .= ''; - - $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status - - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - // Call Hook tabContentViewSupplierInvoice - $parameters = array(); - // Note that $action and $object may be modified by hook - $reshook = $hookmanager->executeHooks('tabContentViewSupplierInvoice', $parameters, $object, $action); - if (empty($reshook)) { - print '
'; - print '
'; - print '
'; - - print ''; - - // Type - print ''; - - // Label - print ''; - print ''; - print ''; - print ''; - - //$form_permission = ($object->statut < FactureFournisseur::STATUS_CLOSED) && $usercancreate && ($object->getSommePaiement() <= 0); - $form_permission = ($object->statut < FactureFournisseur::STATUS_CLOSED) && $usercancreate; - - // Date - print ''; - - // Default terms of the settlement - $langs->load('bills'); - print '"; - print ''; - - // Due date - print ''; - - // Mode of payment - $langs->load('bills'); - print ''; - - // Multicurrency - if (isModEnabled("multicurrency")) { - // Multicurrency code + // Multicurrency rate + if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) + { @@ -3393 +2641 @@ - print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0); + print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0); @@ -3395,3 +2643,2 @@ - if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) { - print ''; - } + if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) + print ''; @@ -3399,3 +2646,6 @@ - print ''; + } + } + + // Bank Account + print '"; + print ''; + + // Incoterms + if (!empty($conf->incoterm->enabled)) + { + print ''; + print ''; + } + + // Other attributes + $cols = 2; + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + print '
'.$langs->trans('Type').''; - print ''; - print $object->getLibType(); - print ''; - if ($object->subtype > 0) { - print ' '.$object->getSubtypeLabel('facture_fourn'); - } - if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) { - $facreplaced = new FactureFournisseur($db); - $facreplaced->fetch($object->fk_facture_source); - print ' '.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).''; - } - if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) { - if ($object->fk_facture_source > 0) { - $facusing = new FactureFournisseur($db); - $facusing->fetch($object->fk_facture_source); - print ' '.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).''; - } else { - $langs->load("errors"); - print ' '.$langs->transnoentities("WarningCorrectedInvoiceNotFound").''; - } - } - - $facidavoir = $object->getListIdAvoirFromInvoice(); - if (count($facidavoir) > 0) { - $invoicecredits = array(); - foreach ($facidavoir as $id) { - $facavoir = new FactureFournisseur($db); - $facavoir->fetch($id); - $invoicecredits[] = $facavoir->getNomUrl(1); - } - print ' '.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits); - print ''; - } - if (isset($objectidnext) && $objectidnext > 0) { - $facthatreplace = new FactureFournisseur($db); - - $facthatreplace->fetch($objectidnext); - print ' '.str_replace('{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities("ReplacedByInvoice", '{s1}')).''; - } - if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_DEPOSIT) { - $discount = new DiscountAbsolute($db); - $result = $discount->fetch(0, 0, $object->id); - if ($result > 0) { - print ' '; - $s = $langs->trans("CreditNoteConvertedIntoDiscount", '{s1}', '{s2}'); - $s = str_replace('{s1}', $object->getLibType(1), $s); - $s = str_replace('{s2}', $discount->getNomUrl(1, 'discount'), $s); - print $s; - print '
'; - } - } - - if ($object->fk_fac_rec_source > 0) { - $tmptemplate = new FactureFournisseurRec($db); - $result = $tmptemplate->fetch($object->fk_fac_rec_source); - if ($result > 0) { - print ' '; - $link = ''.dol_escape_htmltag($tmptemplate->title).''; - $s = $langs->transnoentities("GeneratedFromSupplierTemplate", $link); - - print $s; - print ''; - } + $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none'); @@ -3312,78 +2635,3 @@ - - // Relative and absolute discounts - print ''."\n"; - print '
'.$langs->trans('DiscountStillRemaining'); - print ''; - - $thirdparty = $societe; - $discount_type = 1; - include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; - - print '
'.$form->editfieldkey("Label", 'label', $object->label, $object, $usercancreate).''.$form->editfieldval("Label", 'label', $object->label, $object, $usercancreate).'
'; - print $form->editfieldkey("DateInvoice", 'datef', $object->date, $object, $form_permission, 'datepicker'); - print ''; - print $form->editfieldval("Date", 'datef', $object->date, $object, $form_permission, 'datepicker'); - print '
'; - print ''; - } - print '
'; - print $langs->trans('PaymentConditions'); - print ''; - if ($action != 'editconditions' && $form_permission) { - print 'id.'">'.img_edit($langs->trans('SetConditions'), 1).'
'; - print '
'; - if ($action == 'editconditions') { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id'); - } else { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none'); - } - print "
'; - print $form->editfieldkey("DateMaxPayment", 'date_lim_reglement', $object->date_echeance, $object, $form_permission, 'datepicker'); - print ''; - print $form->editfieldval("DateMaxPayment", 'date_lim_reglement', $object->date_echeance, $object, $form_permission, 'datepicker'); - if ($action != 'editdate_lim_reglement' && $object->hasDelay()) { - print img_warning($langs->trans('Late')); - } - print '
'; - print ''; - if ($action != 'editmode' && $form_permission) { - print ''; - } - print '
'; - print $langs->trans('PaymentMode'); - print 'id.'">'.img_edit($langs->trans('SetMode'), 1).'
'; - print '
'; - if ($action == 'editmode') { - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'DBIT', 1, 1); - } else { - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none'); - } - print '
id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).''; - if ($action == 'editmulticurrencycode') { - $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code'); + print ''; + if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') { + if ($action == 'actualizemulticurrencyrate') { + list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); + } + $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code); @@ -3403 +2653,6 @@ - $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none'); + $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); + if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { + print '
        '; + print ''.$langs->trans("ActualizeCurrency").''; + print '
'; + } @@ -3406,4 +2661,170 @@ - - // Multicurrency rate - if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { - print '
'; + print ''; + print '
'; + print $langs->trans('BankAccount'); + print ''; + if ($action != 'editbankaccount' && $user->rights->fournisseur->facture->creer) + print 'id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'
'; + print '
'; + if ($action == 'editbankaccount') { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + } else { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + } + print "
'; + print '
'; + print $langs->trans('IncotermLabel'); + print ''; + if ($user->rights->fournisseur->facture->creer) print ''.img_edit().''; + else print ' '; + print '
'; + print '
'; + if ($action != 'editincoterm') + { + print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); + } + else + { + print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id); + } + print '
'; + + print '
'; + print '
'; + print '
'; + print '
'; + + print ''; + + if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) + { + // Multicurrency Amount HT + print ''; + print ''; + print ''; + + // Multicurrency Amount VAT + print ''; + print ''; + print ''; + + // Multicurrency Amount TTC + print ''; + print ''; + print ''; + } + + // Amount + print ''; + print ''; + + // Amount Local Taxes + //TODO: Place into a function to control showing by country or study better option + if ($societe->localtax1_assuj == "1") //Localtax1 + { + print ''; + print ''; + print ''; + } + if ($societe->localtax2_assuj == "1") //Localtax2 + { + print ''; + print ''; + print ''; + } + print ''; + + print '
'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).''.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).''.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).''.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$langs->trans('AmountHT').''.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->trans('AmountVAT').''.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'
        '; + if (GETPOST('calculationrule')) $calculationrule = GETPOST('calculationrule', 'alpha'); + else $calculationrule = (empty($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND) ? 'totalofround' : 'roundoftotal'); + if ($calculationrule == 'totalofround') $calculationrulenum = 1; + else $calculationrulenum = 2; + // Show link for "recalculate" + if ($object->getVentilExportCompta() == 0) { + $s = $langs->trans("ReCalculate").' '; + $s .= ''.$langs->trans("Mode1").''; + $s .= ' / '; + $s .= ''.$langs->trans("Mode2").''; + print $form->textwithtooltip($s, $langs->trans("CalculationRuleDesc", $calculationrulenum).'
'.$langs->trans("CalculationRuleDescSupplier"), 2, 1, img_picto('', 'help')); + } + print '
'.$langs->transcountry("AmountLT1", $societe->country_code).''.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->transcountry("AmountLT2", $societe->country_code).''.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'
'; + + /* + * List of payments + */ + + $totalpaye = 0; + + $sign = 1; + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) $sign = - 1; + + $nbrows = 9; $nbcols = 3; + if (!empty($conf->projet->enabled)) $nbrows++; + if (!empty($conf->banque->enabled)) { $nbrows++; $nbcols++; } + if (!empty($conf->incoterm->enabled)) $nbrows++; + if (!empty($conf->multicurrency->enabled)) $nbrows += 5; + + // Local taxes + if ($societe->localtax1_assuj == "1") $nbrows++; + if ($societe->localtax2_assuj == "1") $nbrows++; + + $sql = 'SELECT p.datep as dp, p.ref, p.num_paiement, p.rowid, p.fk_bank,'; + $sql .= ' c.id as paiement_type,'; + $sql .= ' pf.amount,'; + $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid'; + $sql .= ' WHERE pf.fk_facturefourn = '.$object->id; + $sql .= ' ORDER BY p.datep, p.tms'; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + if (!empty($conf->banque->enabled)) print ''; + print ''; + print ''; + print ''; + + if ($num > 0) + { + while ($i < $num) + { + $objp = $db->fetch_object($result); + + $paymentstatic->id = $objp->rowid; + $paymentstatic->datepaye = $db->jdate($objp->dp); + $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid); + $paymentstatic->num_paiement = $objp->num_paiement; + $paymentstatic->payment_code = $objp->payment_code; + + print ''; @@ -3411,2 +2832 @@ - print '
'.($object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).''.$langs->trans('Date').''.$langs->trans('Type').''.$langs->trans('BankAccount').''.$langs->trans('Amount').' 
'; - } - print '
'; - print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0); + print $paymentstatic->getNomUrl(1); @@ -3414,8 +2834,17 @@ - if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { - print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'
'; - print '
'; - if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') { - if ($action == 'actualizemulticurrencyrate') { - list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); + print ''.dol_print_date($db->jdate($objp->dp), 'day').''; + print $form->form_modes_reglement(null, $objp->paiement_type, 'none').' '.$objp->num_paiement; + print ''; + if ($objp->baid > 0) print $bankaccountstatic->getNomUrl(1, 'transactions'); + print ''.price($sign * $objp->amount).''; + if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $user->socid == 0) + { + print 'rowid.'">'; + print img_delete(); + print ''; + } + print '
'.$langs->trans("None").'
'.$langs->trans('AlreadyPaid').' :'.price($totalpaye).'
'.$langs->trans("Billed").' :'.price($object->total_ttc).'
'.$langs->trans('RemainderToPay').' :'.price($resteapayer).'
'; + if ($object->type != FactureFournisseur::TYPE_DEPOSIT) + print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits'); + else + print $langs->trans('AlreadyPaid'); + print ' : 0) ? ' class="amountalreadypaid"' : '').'>'.price($totalpaye).' 
'; + if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) + print $langs->trans("CreditNote").' '; + if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) + print $langs->trans("Deposit").' '; + print $invoice->getNomUrl(0); + print ' :'.price($obj->amount_ttc).''; + print 'rowid.'">'.img_delete().''; @@ -3433,303 +2939,6 @@ - } - } - - // Bank Account - if (isModEnabled("banque")) { - print '
'; - print ''; - } - print '
'; - print $langs->trans('BankAccount'); - print ''; - if ($action != 'editbankaccount' && $usercancreate) { - print 'id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'
'; - print '
'; - if ($action == 'editbankaccount') { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); - } else { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); - } - print "
'; - print ''; - } - print '
'; - print $langs->trans('VATReverseCharge'); - print ''; - if ($action != 'editvatreversecharge' && $usercancreate) { - print 'id.'">'.img_edit($langs->trans('SetVATReverseCharge'), 1).'
'; - print '
'; - if ($action == 'editvatreversecharge') { - print '
'; - print ''; - print ''; - - print 'vat_reverse_charge == '1' ? ' checked ' : '') . '>'; - - print ''; - print '
'; - } else { - print 'vat_reverse_charge == '1' ? ' checked ' : '') . ' disabled>'; - } - print '
'; - print '
'; - print $langs->trans('IncotermLabel'); - print ''; - if ($usercancreate) { - print ''.img_edit().''; - } else { - print ' '; - } - print '
'; - print '
'; - if ($action != 'editincoterm') { - print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); - } else { - print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id); - } - print '
'; - print ''; - if ($action != 'edittransportmode' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { - print ''; - } - print '
'; - print $langs->trans('IntracommReportTransportMode'); - print 'id.'">'.img_edit().'
'; - print '
'; - if ($action == 'edittransportmode') { - $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?id='.$object->id, $object->transport_mode_id, 'transport_mode_id', 1, 1); - } else { - $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?id='.$object->id, $object->transport_mode_id, 'none'); - } - print '
'; - print '
'; - - print '
'; - print '
'; - - print ''; - - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; - } - print ''; - - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; - } - print ''; - - if ($societe->localtax1_assuj == "1") { //Localtax1 - print ''; - print ''; - print ''; - print ''; - } - if ($societe->localtax2_assuj == "1") { //Localtax2 - print ''; - print ''; - print ''; - print ''; - } - - print ''; - print ''; - print ''; - if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) { - print ''; - } - print ''; - - print '
' . $langs->trans('AmountHT') . '' . price($object->total_ht, '', $langs, 0, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_ht, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->trans('AmountVAT') . ''; - if (GETPOST('calculationrule')) { - $calculationrule = GETPOST('calculationrule', 'alpha'); - } else { - $calculationrule = (!getDolGlobalString('MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND') ? 'totalofround' : 'roundoftotal'); - } - if ($calculationrule == 'totalofround') { - $calculationrulenum = 1; - } else { - $calculationrulenum = 2; - } - // Show link for "recalculate" - if ($object->getVentilExportCompta() == 0) { - $s = '' . $langs->trans("ReCalculate") . ' '; - $s .= '' . $langs->trans("Mode1") . ''; - $s .= ' / '; - $s .= '' . $langs->trans("Mode2") . ''; - print '
'; - print $form->textwithtooltip($s, $langs->trans("CalculationRuleDesc", $calculationrulenum) . '
' . $langs->trans("CalculationRuleDescSupplier"), 2, 1, img_picto('', 'help'), '', 3, '', 0, 'recalculate'); - print '       '; - print '
'; - } - print price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency); - print '
' . price($object->multicurrency_total_tva, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
' . $langs->transcountry("AmountLT1", $societe->country_code) . '' . price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency) . '
' . $langs->transcountry("AmountLT2", $societe->country_code) . '' . price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency) . '
' . $langs->trans('AmountTTC') . '' . price($object->total_ttc, '', $langs, 0, -1, -1, $conf->currency) . '' . price($object->multicurrency_total_ttc, '', $langs, 0, -1, -1, $object->multicurrency_code) . '
'; - - - // List of payments - - $totalpaid = 0; - - $sign = 1; - if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) { - $sign = - 1; - } - - $nbrows = 9; - $nbcols = 3; - if (isModEnabled('project')) { - $nbrows++; - } - if (isModEnabled("banque")) { - $nbrows++; - $nbcols++; - } - if (isModEnabled('incoterm')) { - $nbrows++; - } - if (isModEnabled("multicurrency")) { - $nbrows += 5; - } - - // Local taxes - if ($societe->localtax1_assuj == "1") { - $nbrows++; - } - if ($societe->localtax2_assuj == "1") { - $nbrows++; - } - - $sql = 'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,'; - $sql .= ' c.id as payment_type, c.code as payment_code,'; - $sql .= ' pf.amount,'; - $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid'; - $sql .= ' WHERE pf.fk_facturefourn = '.((int) $object->id); - $sql .= ' ORDER BY p.datep, p.tms'; - - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - $i = 0; - - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - if (isModEnabled("banque")) { - print ''; - } - print ''; - print ''; - print ''; - - if ($num > 0) { - while ($i < $num) { - $objp = $db->fetch_object($result); - - $paymentstatic->id = $objp->rowid; - $paymentstatic->datepaye = $db->jdate($objp->dp); - $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid); - $paymentstatic->num_payment = $objp->num_payment; - - $paymentstatic->paiementcode = $objp->payment_code; - $paymentstatic->type_code = $objp->payment_code; - $paymentstatic->type_label = $objp->payment_type; - - print ''; - print ''; - print ''; - $s = $form->form_modes_reglement(null, $objp->payment_type, 'none', '', 1, 0, '', 1).' '.$objp->num_payment; - print ''; - if (isModEnabled("banque")) { - $bankaccountstatic->id = $objp->baid; - $bankaccountstatic->ref = $objp->baref; - $bankaccountstatic->label = $objp->baref; - $bankaccountstatic->number = $objp->banumber; - - if (isModEnabled('accounting')) { - $bankaccountstatic->account_number = $objp->account_number; - - $accountingjournal = new AccountingJournal($db); - $accountingjournal->fetch($objp->fk_accountancy_journal); - $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1); - } - - print ''; - } - print ''; - print ''; - print ''; - $totalpaid += $objp->amount; - $i++; - } - } else { - print ''; - } - - /* - if ($object->paye == 0) - { - print ''; - print ''; - - $resteapayer = $object->total_ttc - $totalpaid; - - print ''; - print ''; - } - */ - - $db->free($result); + $i++; + if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) + $creditnoteamount += $obj->amount_ttc; + if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) + $depositamount += $obj->amount_ttc; + } @@ -3740,115 +2949,42 @@ - if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE) { - // Total already paid - print ''; - - //$resteapayer = $object->total_ttc - $totalpaid; - $resteapayeraffiche = $resteapayer; - - $cssforamountpaymentcomplete = 'amountpaymentcomplete'; - - // Loop on each credit note or deposit amount applied - $creditnoteamount = 0; - $depositamount = 0; - - $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; - $sql .= " re.description, re.fk_invoice_supplier_source"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re"; - $sql .= " WHERE fk_invoice_supplier = ".((int) $object->id); - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - $invoice = new FactureFournisseur($db); - while ($i < $num) { - $obj = $db->fetch_object($resql); - $invoice->fetch($obj->fk_invoice_supplier_source); - print ''; - print ''; - print ''; - $i++; - if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) { - $creditnoteamount += $obj->amount_ttc; - } - if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) { - $depositamount += $obj->amount_ttc; - } - } - } else { - dol_print_error($db); - } - - // Paye partiellement 'escompte' - if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'discount_vat') { - print ''; - $resteapayeraffiche = 0; - $cssforamountpaymentcomplete = 'amountpaymentneutral'; - } - // Paye partiellement ou Abandon 'badsupplier' - if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'badsupplier') { - print ''; - // $resteapayeraffiche=0; - $cssforamountpaymentcomplete = 'amountpaymentneutral'; - } - // Paye partiellement ou Abandon 'product_returned' - if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'product_returned') { - print ''; - $resteapayeraffiche = 0; - $cssforamountpaymentcomplete = 'amountpaymentneutral'; - } - // Paye partiellement ou Abandon 'abandon' - if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'abandon') { - print ''; - $resteapayeraffiche = 0; - $cssforamountpaymentcomplete = 'amountpaymentneutral'; - } - - // Billed - print ''; - - // Remainder to pay - print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = 'amountpaymentneutral'; + } + // Paye partiellement ou Abandon 'badsupplier' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'badsupplier') { + print ''; + // $resteapayeraffiche=0; + $cssforamountpaymentcomplete = 'amountpaymentneutral'; + } + // Paye partiellement ou Abandon 'product_returned' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'product_returned') { + print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = 'amountpaymentneutral'; + } + // Paye partiellement ou Abandon 'abandon' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'abandon') { + print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = 'amountpaymentneutral'; + } + + // Billed + print ''; + + // Remainder to pay + print ''; - print ''; - - // Remainder to pay Multicurrency - if (isModEnabled('multicurrency') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { - print ''; - print ''; - } - } else { // Credit note - $cssforamountpaymentcomplete = 'amountpaymentneutral'; - - // Total already paid back - print ''; - - // Billed - print ''; - - // Remainder to pay back - print ''; + print ''; + print ''; + } + else // Credit note + { + $cssforamountpaymentcomplete = 'amountpaymentneutral'; + + // Total already paid back + print ''; + + // Billed + print ''; + + // Remainder to pay back + print ''; - print ''; - print ''; - - // Remainder to pay back Multicurrency - if (isModEnabled('multicurrency') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) { - print ''; - print ''; - } - - // Sold credit note - // print ''; - // print ''; - } - - print '
'.($object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).''.$langs->trans('Date').''.$langs->trans('Type').''.$langs->trans('BankAccount').''.$langs->trans('Amount').' 
'; - print $paymentstatic->getNomUrl(1); - print ''.dol_print_date($db->jdate($objp->dp), 'day').''; - print $s; - print ''; - if ($objp->baid > 0) { - print $bankaccountstatic->getNomUrl(1, 'transactions'); - } - print ''.price($sign * $objp->amount).''; - if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $user->socid == 0) { - print 'rowid.'">'; - print img_delete(); - print ''; - } - print '
'.$langs->trans("None").'
'.$langs->trans('AlreadyPaid').' :'.price($totalpaid).'
'.$langs->trans("Billed").' :'.price($object->total_ttc).'
'.$langs->trans('RemainderToPay').' :'.price($resteapayer).'
'; - print ''; - if ($object->type != FactureFournisseur::TYPE_DEPOSIT) { - print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits'); - } else { - print $langs->trans('AlreadyPaid'); - } - print ''; - print ' 0) ? ' class="amountalreadypaid"' : '').'>'.price($totalpaid).' 
'; - if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) { - print $langs->trans("CreditNote").' '; - } - if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) { - print $langs->trans("Deposit").' '; - } - print $invoice->getNomUrl(0); - print ' :'.price($obj->amount_ttc).''; - print 'rowid.'">'; - print img_picto($langs->transnoentitiesnoconv("RemoveDiscount"), 'unlink'); - print ''; - print '
'; - print ''; - print $form->textwithpicto($langs->trans("Discount"), $langs->trans("HelpEscompte"), - 1); - print ''; - print ''.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).' 
'; - print ''; - print $form->textwithpicto($langs->trans("Abandoned"), $langs->trans("HelpAbandonBadCustomer"), - 1); - print ''; - print ''.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).' 
'; - print ''; - print $form->textwithpicto($langs->trans("ProductReturned"), $langs->trans("HelpAbandonProductReturned"), - 1); - print ''; - print ''.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).' 
'; - $text = $langs->trans("HelpAbandonOther"); - if ($object->close_note) { - $text .= '

'.$langs->trans("Reason").':'.$object->close_note; - } - print ''; - print $form->textwithpicto($langs->trans("Abandoned"), $text, - 1); - print ''; - print '
'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).' 
'; - print ''; - print $langs->trans("Billed"); - print ''; - print ''.price($object->total_ttc).' 
'; - print ''; + // Paye partiellement 'escompte' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'discount_vat') { + print '
'; + print $form->textwithpicto($langs->trans("Discount").':', $langs->trans("HelpEscompte"), - 1); + print ''.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' 
'; + print $form->textwithpicto($langs->trans("Abandoned").':', $langs->trans("HelpAbandonBadCustomer"), - 1); + print ''.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' 
'; + print $form->textwithpicto($langs->trans("ProductReturned").':', $langs->trans("HelpAbandonProductReturned"), - 1); + print ''.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' 
'; + $text = $langs->trans("HelpAbandonOther"); + if ($object->close_note) + $text .= '

'.$langs->trans("Reason").':'.$object->close_note; + print $form->textwithpicto($langs->trans("Abandoned").':', $text, - 1); + print '
'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' 
'.$langs->trans("Billed").' :'.price($object->total_ttc).' 
'; + if ($resteapayeraffiche >= 0) @@ -3856,33 +2992,21 @@ - if ($resteapayeraffiche < 0) { - print ' ('.$langs->trans('NegativeIfExcessPaid').')'; - } - print ''; - print ''.price($resteapayeraffiche).' 
'; - print ''; - print $langs->trans('RemainderToPayMulticurrency'); - if ($resteapayeraffiche < 0) { - print ' ('.$langs->trans('NegativeIfExcessPaid').')'; - } - print ''; - print ''.(!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency).' '.price(price2num($multicurrency_resteapayer, 'MT')).' 
'; - print $langs->trans('AlreadyPaidBack'); - print ' :'.price($sign * $totalpaid).' 
'.$langs->trans("Billed").' :'.price($sign * $object->total_ttc).' 
'; - print ''; + else + print $langs->trans('ExcessPaid'); + print ' :'.price($resteapayeraffiche).' 
'; + print $langs->trans('AlreadyPaidBack'); + print ' :'.price($sign * $totalpaye).' 
'.$langs->trans("Billed").' :'.price($sign * $object->total_ttc).' 
'; + if ($resteapayeraffiche <= 0) @@ -3890,48 +3014,88 @@ - if ($resteapayeraffiche > 0) { - print ' ('.$langs->trans('NegativeIfExcessRefunded').')'; - } - print ''.price($sign * $resteapayeraffiche).' 
'; - print ''; - print $langs->trans('RemainderToPayBackMulticurrency'); - if ($resteapayeraffiche> 0) { - print ' ('.$langs->trans('NegativeIfExcessRefunded').')'; - } - print ''; - print ''.(!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency).' '.price(price2num($sign * $object->multicurrency_tx * $resteapayeraffiche, 'MT')).' 
'.$langs->trans('TotalTTC').' :'.price($sign * - // $object->total_ttc).' 
'; - print '
'; - - print '
'; - print '
'; - - print '

'; - - if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) { - $blocname = 'contacts'; - $title = $langs->trans('ContactsAddresses'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } - - if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) { - $colwidth = 20; - $blocname = 'notes'; - $title = $langs->trans('Notes'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } - - + else + print $langs->trans('ExcessPaid'); + print ' :'; + print ''.price($sign * $resteapayeraffiche).''; + print ' '; + + // Sold credit note + // print ''.$langs->trans('TotalTTC').' :'; + // print ''.price($sign * + // $object->total_ttc).' '; + } + + print ''; + print '
'; + + print ''; + print ''; + print ''; + + 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)) + { + $colwidth = 20; + $blocname = 'notes'; + $title = $langs->trans('Notes'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + + /* + * Lines + */ + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + + if (!empty($conf->use_javascript_ajax) && $object->statut == FactureFournisseur::STATUS_DRAFT) { + include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; + } + + print '
'; + print ''; + + global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax; + $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1; + $senderissupplier = 2; // $senderissupplier=2 is same than 1 but disable test on minimum qty and disable autofill qty with minimum. + //if (! empty($conf->global->SUPPLIER_INVOICE_WITH_NOPRICEDEFINED)) $senderissupplier=2; + if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) $senderissupplier = 1; + + // Show object lines + if (!empty($object->lines)) + $ret = $object->printObjectLines($action, $societe, $mysoc, $lineid, 1); + + $num = count($object->lines); + + // Form to add new line + if ($object->statut == FactureFournisseur::STATUS_DRAFT && $user->rights->fournisseur->facture->creer) + { + if ($action != 'editline') + { + // Add free products/services + $object->formAddObjectLine(1, $societe, $mysoc); + + $parameters = array(); + $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + } + } + + print '
'; + print '
'; + print '
'; + + dol_fiche_end(); + + + if ($action != 'presend') + { @@ -3939,63 +3103,2 @@ - * Lines - */ - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - if (!empty($conf->use_javascript_ajax) && $object->statut == FactureFournisseur::STATUS_DRAFT) { - include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; - } - - print '
'; - print ''; - - global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax; - $forceall = 1; - $dateSelector = 0; - $inputalsopricewithtax = 1; - $senderissupplier = 2; // $senderissupplier=2 is same than 1 but disable test on minimum qty and disable autofill qty with minimum. - //if (!empty($conf->global->SUPPLIER_INVOICE_WITH_NOPRICEDEFINED)) $senderissupplier=2; - if (getDolGlobalString('SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY')) { - $senderissupplier = 1; - } - - // Show object lines (result may vary according to hidden option MAIN_NO_INPUT_PRICE_WITH_TAX) - if (!empty($object->lines)) { - $object->printObjectLines($action, $societe, $mysoc, $lineid, 1); - } - - $num = count($object->lines); - - // Form to add new line - if ($object->statut == FactureFournisseur::STATUS_DRAFT && $usercancreate) { - if ($action != 'editline') { - // Add free products/services - - $parameters = array(); - $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - } - if (empty($reshook)) { - $object->formAddObjectLine(1, $societe, $mysoc); - } - } - } - - print '
'; - print '
'; - print '
'; - } - - print dol_get_fiche_end(); - - - if ($action != 'presend') { - /* - * Buttons actions - */ + * Buttons actions + */ @@ -4007,4 +3110,6 @@ - // modified by hook - if (empty($reshook)) { - // Modify a validated invoice with no payments - if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $action != 'confirm_edit' && $object->getSommePaiement() == 0 && $usercancreate) { + // modified by hook + if (empty($reshook)) + { + // Modify a validated invoice with no payments + if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $action != 'confirm_edit' && $object->getSommePaiement() == 0 && $user->rights->fournisseur->facture->creer) + { @@ -4014,4 +3119,7 @@ - if ($ventilExportCompta == 0) { - print ''.$langs->trans('Modify').''; - } else { - print ''.$langs->trans('Modify').''; + if ($ventilExportCompta == 0) + { + print ''; + } + else + { + print '
'.$langs->trans('Modify').'
'; @@ -4024 +3132 @@ - // Reopen a standard paid invoice + // Reopen a standard paid invoice @@ -4026,23 +3134,13 @@ - || ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && empty($discount->id)) - || ($object->type == FactureFournisseur::TYPE_DEPOSIT && empty($discount->id))) - && ($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED)) { // A paid invoice (partially or completely) - if (!$objectidnext && $object->close_code != 'replaced' && $usercancreate) { // Not replaced by another invoice - print ''.$langs->trans('ReOpen').''; - } else { - if ($usercancreate) { - print ''.$langs->trans('ReOpen').''; - } elseif (!getDolGlobalString('MAIN_BUTTON_HIDE_UNAUTHORIZED')) { - print ''.$langs->trans('ReOpen').''; - } - } - } - - // Validate - if ($action != 'confirm_edit' && $object->statut == FactureFournisseur::STATUS_DRAFT) { - if (count($object->lines)) { - if ($usercanvalidate) { - print ''.$langs->trans('Validate').''; - } else { - print ''.$langs->trans('Validate').''; + || ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && empty($discount->id))) + && ($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED)) // A paid invoice (partially or completely) + { + if (!$facidnext && $object->close_code != 'replaced' && $user->rights->fournisseur->facture->creer) // Not replaced by another invoice + { + print ''; + } + else + { + if ($user->rights->fournisseur->facture->creer) { + print '
'.$langs->trans('ReOpen').'
'; + } elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) { + print '
'.$langs->trans('ReOpen').'
'; @@ -4055,5 +3153,5 @@ - if (($object->statut == FactureFournisseur::STATUS_VALIDATED || $object->statut == FactureFournisseur::STATUS_CLOSED)) { - if ($usercansend) { - print ''.$langs->trans('SendMail').''; - } else { - print ''.$langs->trans('SendMail').''; + if (($object->statut == FactureFournisseur::STATUS_VALIDATED || $object->statut == FactureFournisseur::STATUS_CLOSED)) + { + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->fournisseur->supplier_invoice_advance->send) + { + print ''; @@ -4061,6 +3159,17 @@ - } - } - - // Create payment - if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE && $object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0) { - print ''.$langs->trans('DoPayment').''; // must use facid because id is for payment id not invoice + else print '
'.$langs->trans('SendMail').'
'; + } + } + + // Make payments + if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE && $action != 'confirm_edit' && $object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $user->socid == 0) + { + print ''; // must use facid because id is for payment id not invoice + } + + // Classify paid + if ($action != 'confirm_edit' && $object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $user->socid == 0) + { + print ''; + + //print ''.$langs->trans('ClassifyPaid').''; @@ -4072,5 +3181,5 @@ - if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0) { - if ($resteapayer == 0) { - print ''.$langs->trans('DoPaymentBack').''; - } else { - print ''.$langs->trans('DoPaymentBack').''; + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0) + { + if ($resteapayer == 0) + { + print '
'.$langs->trans('DoPaymentBack').'
'; @@ -4077,0 +3187,4 @@ + else + { + print ''; + } @@ -4081,2 +3194,3 @@ - if ($object->type == FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) < 0 && $usercancreate && empty($discount->id)) { - print ''.$langs->trans('ConvertExcessPaidToReduc').''; + if ($object->type == FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) < 0 && $user->rights->fournisseur->facture->creer && empty($discount->id)) + { + print ''; @@ -4085,2 +3199,2 @@ - if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $usercancreate - && (getDolGlobalString('SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED') || $object->getSommePaiement() == 0) + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->fournisseur->facture->creer + && (!empty($conf->global->SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $object->getSommePaiement() == 0) @@ -4088 +3202 @@ - print ''.$langs->trans('ConvertToReduc').''; + print ''; @@ -4091,26 +3205,24 @@ - if ($object->type == FactureFournisseur::TYPE_DEPOSIT && $usercancreate && $object->statut > 0 && empty($discount->id)) { - print ''.$langs->trans('ConvertToReduc').''; - } - } - - // Classify paid - if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && ( - ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE && $object->type != FactureFournisseur::TYPE_DEPOSIT && ($resteapayer <= 0 || (getDolGlobalString('SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $object->total_ttc == $resteapayer))) || - ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $resteapayer >= 0) || - ($object->type == FactureFournisseur::TYPE_DEPOSIT && $object->total_ttc > 0 && ($resteapayer == 0 || (getDolGlobalString('SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') && $object->total_ttc == $resteapayer))) - ) - ) { - print ''.$langs->trans('ClassifyPaid').''; - } - - // Classify 'closed not completely paid' (possible if validated and not yet filed paid) - if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $resteapayer > 0 && (!getDolGlobalString('SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID') || $object->total_ttc != $resteapayer)) { - if ($totalpaid > 0 || $totalcreditnotes > 0) { - // If one payment or one credit note was linked to this invoice - print ''.$langs->trans('ClassifyPaidPartially').''; - } else { - if (!getDolGlobalString('INVOICE_CAN_NEVER_BE_CANCELED')) { - print ''.$langs->trans('ClassifyCanceled').''; - } - } - } + if ($object->type == FactureFournisseur::TYPE_DEPOSIT && $object->paye == 1 && $resteapayer == 0 && $user->rights->fournisseur->facture->creer && empty($discount->id)) + { + print ''; + } + } + + // Validate + if ($action != 'confirm_edit' && $object->statut == FactureFournisseur::STATUS_DRAFT) + { + if (count($object->lines)) + { + if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->facture->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate))) + { + print ''; + } + else + { + print ''; + } + } + } @@ -4119 +3231 @@ - /*if (isModEnabled('agenda') && !empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a "workflow" action so should appears somewhere else on page. + /*if ($conf->agenda->enabled && ! empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a "workflow" action so should appears somewhere else on page. @@ -4123,0 +3236,6 @@ + // Clone + if ($action != 'edit' && $user->rights->fournisseur->facture->creer) + { + print ''; + } + @@ -4125,19 +3243,9 @@ - if (($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_DEPOSIT) && $object->statut > 0 && $usercancreate) { - if (!$objectidnext) { - print ''.$langs->trans("CreateCreditNote").''; - } - } - - // Clone - if ($action != 'edit' && $usercancreate) { - print 'socid.'">'.$langs->trans('ToClone').''; - } - - // Clone as predefined / Create template - if (($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_DEPOSIT) && $object->statut == 0 && $usercancreate) { - if (!$objectidnext && count($object->lines) > 0) { - print ''.$langs->trans("ChangeIntoRepeatableInvoice").''; - } - } - - // Delete + if (($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_DEPOSIT) && $object->statut > 0 && $user->rights->fournisseur->facture->creer) + { + if (!$objectidnext) + { + print ''; + } + } + + // Delete @@ -4145,24 +3253,28 @@ - if ($action != 'confirm_edit' && ($usercandelete || ($usercancreate && $isErasable == 1))) { // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions) - $enableDelete = false; - $htmltooltip = ''; - $params = (empty($conf->use_javascript_ajax) ? array() : array('attr' => array('class' => 'reposition'))); - //var_dump($isErasable); var_dump($params); - if ($isErasable == -4) { - $htmltooltip = $langs->trans("DisabledBecausePayments"); - } elseif ($isErasable == -3) { // Should never happen with supplier invoice - $htmltooltip = $langs->trans("DisabledBecauseNotLastSituationInvoice"); - } elseif ($isErasable == -2) { // Should never happen with supplier invoice - $htmltooltip = $langs->trans("DisabledBecauseNotLastInvoice"); - } elseif ($isErasable == -1) { - $htmltooltip = $langs->trans("DisabledBecauseDispatchedInBookkeeping"); - } elseif ($isErasable <= 0) { // Any other cases - $htmltooltip = $langs->trans("DisabledBecauseNotErasable"); - } else { - $enableDelete = true; - $htmltooltip = ''; - } - print dolGetButtonAction($htmltooltip, $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), $object->id, $enableDelete, $params); - } - print ''; - - if ($action != 'confirm_edit') { + if ($action != 'confirm_edit' && ($user->rights->fournisseur->facture->supprimer || ($user->rights->fournisseur->facture->creer && $isErasable == 1))) // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions) + { + //var_dump($isErasable); + if ($isErasable == -4) { + print ''; + } + elseif ($isErasable == -3) { // Should never happen with supplier invoice + print ''; + } + elseif ($isErasable == -2) { // Should never happen with supplier invoice + print ''; + } + elseif ($isErasable == -1) { + print ''; + } + elseif ($isErasable <= 0) // Any other cases + { + print ''; + } + else + { + print ''; + } + } + print ''; + + if ($action != 'confirm_edit') + { @@ -4172,2 +3284,2 @@ - * Generated documents - */ + * Documents generes + */ @@ -4178,3 +3290,3 @@ - $genallowed = $usercanread; - $delallowed = $usercancreate; - $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (!getDolGlobalString('INVOICE_SUPPLIER_ADDON_PDF') ? '' : $conf->global->INVOICE_SUPPLIER_ADDON_PDF)); + $genallowed = $user->rights->fournisseur->facture->lire; + $delallowed = $user->rights->fournisseur->facture->creer; + $modelpdf = (!empty($object->modelpdf) ? $object->modelpdf : (empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF) ? '' : $conf->global->INVOICE_SUPPLIER_ADDON_PDF)); @@ -4189 +3301,3 @@ - print '
'; + print '
'; + //print ''; + //print '
'; @@ -4196 +3310,2 @@ - print '
'; + print ''; + //print ''; @@ -4211 +3326 @@ - $trackid = 'sinv'.$object->id; + $trackid = 'sin'.$object->id; --- /tmp/dsg/dolibarr/htdocs/fourn/facture/github_19.0.3_contact.php +++ /tmp/dsg/dolibarr/htdocs/fourn/facture/client_contact.php @@ -2,6 +2,4 @@ -/* Copyright (C) 2005 Patrick Rouillon - * Copyright (C) 2005-2015 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2017 Ferran Marcet - * Copyright (C) 2021 Frédéric France - * Copyright (C) 2023 Christian Foellmann +/* Copyright (C) 2005 Patrick Rouillon + * Copyright (C) 2005-2015 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2017 Ferran Marcet @@ -29 +26,0 @@ -// Load Dolibarr environment @@ -36 +33 @@ -if (isModEnabled('project')) { +if (!empty($conf->projet->enabled)) { @@ -44 +41 @@ -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); @@ -47,3 +44 @@ -if ($user->socid) { - $socid = $user->socid; -} +if ($user->socid) $socid = $user->socid; @@ -51 +45,0 @@ -$hookmanager->initHooks(array('invoicesuppliercardcontact','invoicesuppliercontactcard', 'globalcard')); @@ -55,2 +48,0 @@ -$usercancreate = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); -$permissiontoadd = $usercancreate; @@ -59,52 +51,58 @@ - * Actions - */ - -$parameters = array('id'=>$id); -$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); -if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -} - -/* - * Add a new contact - */ - -if (empty($reshook)) { - if ($action == 'addcontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { - $result = $object->fetch($id, $ref); - - if ($result > 0 && $id > 0) { - $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); - } - - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("errors"); - setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - } elseif ($action == 'swapstatut' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { - // bascule du statut d'un contact - if ($object->fetch($id)) { - $result = $object->swapContactStatus(GETPOST('ligne', 'int')); - } else { - dol_print_error($db); - } - } elseif ($action == 'deletecontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { - // Efface un contact - $object->fetch($id); - $result = $object->delete_contact(GETPOST("lineid", 'int')); - - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - dol_print_error($db); - } + * Ajout d'un nouveau contact + */ + +if ($action == 'addcontact' && $user->rights->fournisseur->facture->creer) +{ + $result = $object->fetch($id, $ref); + + 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; + } + else + { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } +} + +// bascule du statut d'un contact +elseif ($action == 'swapstatut' && $user->rights->fournisseur->facture->creer) +{ + if ($object->fetch($id)) + { + $result = $object->swapContactStatus(GETPOST('ligne')); + } + else + { + dol_print_error($db); + } +} + +// Efface un contact +elseif ($action == 'deletecontact' && $user->rights->fournisseur->facture->creer) +{ + $object->fetch($id); + $result = $object->delete_contact($_GET["lineid"]); + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else { + dol_print_error($db); @@ -117,0 +116,5 @@ + +$title = $langs->trans('SupplierInvoice')." - ".$langs->trans('ContactsAddresses'); +$helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores"; +llxHeader('', $title, $helpurl); + @@ -130,2 +133,4 @@ -if ($id > 0 || !empty($ref)) { - if ($object->fetch($id, $ref) > 0) { +if ($id > 0 || !empty($ref)) +{ + if ($object->fetch($id, $ref) > 0) + { @@ -136,4 +140,0 @@ - $title = $object->ref." - ".$langs->trans('ContactsAddresses'); - $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores"; - llxHeader('', $title, $helpurl); - @@ -142,3 +143,3 @@ - print dol_get_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice'); - - $linkback = ''.$langs->trans("BackToList").''; + dol_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), -1, 'bill'); + + $linkback = ''.$langs->trans("BackToList").''; @@ -147,10 +148,9 @@ - // Ref supplier - $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1); - // Thirdparty - $morehtmlref .= '
'.$object->thirdparty->getNomUrl(1); - if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) { - $morehtmlref .= ' '; - } - // Project - if (isModEnabled('project')) { + // Ref supplier + $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); + if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' ('.$langs->trans("OtherBills").')'; + // Project + if (!empty($conf->projet->enabled)) + { @@ -158,5 +158,16 @@ - $morehtmlref .= '
'; - if (0) { - $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); - if ($action != 'classify') { - $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; + $morehtmlref .= '
'.$langs->trans('Project').' '; + if ($user->rights->facture->creer) + { + if ($action != 'classify') + //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + $morehtmlref .= ' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref .= ''; + $morehtmlref .= '
'; + } else { + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); @@ -164 +174,0 @@ - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); @@ -169,4 +179,5 @@ - $morehtmlref .= $proj->getNomUrl(1); - if ($proj->title) { - $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; - } + $morehtmlref .= ''; + $morehtmlref .= $proj->ref; + $morehtmlref .= ''; + } else { + $morehtmlref .= ''; @@ -178 +189 @@ - $object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status + $object->totalpaye = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status @@ -182 +192,0 @@ - /* @@ -184 +193,0 @@ - print '
'; @@ -191 +199,0 @@ - print ''; @@ -193,2 +201,2 @@ - print ''; - if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) { + if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) + { @@ -197,3 +205,4 @@ - print ' '.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)); - } - if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) { + print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')'; + } + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) + { @@ -202 +211 @@ - print ' '.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)); + print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')'; @@ -206,3 +215,8 @@ - if (count($facidavoir) > 0) { - $invoicecredits = array(); - foreach ($facidavoir as $facid) { + if (count($facidavoir) > 0) + { + print ' ('.$langs->transnoentities("InvoiceHasAvoir"); + $i = 0; + foreach ($facidavoir as $fid) + { + if ($i == 0) print ' '; + else print ','; @@ -210,2 +224,2 @@ - $facavoir->fetch($facid); - $invoicecredits[] = $facavoir->getNomUrl(1); + $facavoir->fetch($fid); + print $facavoir->getNomUrl(1); @@ -213,7 +227,8 @@ - print ' '.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits); - } - //if ($facidnext > 0) { - // $facthatreplace = new FactureFournisseur($db); - // $facthatreplace->fetch($facidnext); - // print ' '.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)); - //} + print ')'; + } + if ($facidnext > 0) + { + $facthatreplace = new FactureFournisseur($db); + $facthatreplace->fetch($facidnext); + print ' ('.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)).')'; + } @@ -227,24 +242,19 @@ - print ''; - - print '
'; - print '
'; - - print ''; - - // Amount - print ''; - print ''; - - // Amount Local Taxes - //TODO: Place into a function to control showing by country or study better option - if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { //Localtax1 - print ''; - print ''; - print ''; - } - if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { //Localtax2 - print ''; - print ''; - print ''; - } - print ''; + // Amount + print ''; + print ''; + + // Amount Local Taxes + //TODO: Place into a function to control showing by country or study better option + if ($societe->localtax1_assuj == "1") //Localtax1 + { + print ''; + print ''; + print ''; + } + if ($societe->localtax2_assuj == "1") //Localtax2 + { + print ''; + print ''; + print ''; + } + print ''; @@ -253,9 +263,4 @@ - print ''; - - print ''; - */ - - print dol_get_fiche_end(); - - //print '
'; - //print '
'; + + dol_fiche_end(); + + print '
'; @@ -265 +270,3 @@ - } else { + } + else + { --- /tmp/dsg/dolibarr/htdocs/fourn/facture/github_19.0.3_document.php +++ /tmp/dsg/dolibarr/htdocs/fourn/facture/client_document.php @@ -8,2 +8 @@ - * Copyright (C) 2017 Ferran Marcet - * Copyright (C) 2021 Frédéric France + * Copyright (C) 2017 Ferran Marcet @@ -31 +29,0 @@ -// Load Dolibarr environment @@ -39 +37 @@ -if (isModEnabled('project')) { +if (!empty($conf->projet->enabled)) { @@ -45,2 +43,2 @@ -$id = GETPOST('facid', 'int') ? GETPOST('facid', 'int') : GETPOST('id', 'int'); -$action = GETPOST('action', 'aZ09'); +$id = GETPOST('facid', 'int') ?GETPOST('facid', 'int') : GETPOST('id', 'int'); +$action = GETPOST('action', 'alpha'); @@ -51,3 +49 @@ -if ($user->socid) { - $socid = $user->socid; -} +if ($user->socid) $socid = $user->socid; @@ -55 +50,0 @@ -$hookmanager->initHooks(array('invoicesuppliercarddocument')); @@ -59,2 +54,2 @@ -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); @@ -62,3 +57 @@ -if (empty($page) || $page == -1) { - $page = 0; -} // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 @@ -68,6 +61,2 @@ -if (!$sortorder) { - $sortorder = "ASC"; -} -if (!$sortfield) { - $sortfield = "name"; -} +if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) $sortfield = "name"; @@ -76 +65,2 @@ -if ($object->fetch($id, $ref)) { +if ($object->fetch($id, $ref)) +{ @@ -82,2 +71,0 @@ -$permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); // Used by the include of actions_setnotes.inc.php - @@ -89 +77 @@ -include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; +include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; @@ -98 +86 @@ -$title = $object->ref." - ".$langs->trans('Documents'); +$title = $langs->trans('SupplierInvoice')." - ".$langs->trans('Documents'); @@ -102 +90,2 @@ -if ($object->id > 0) { +if ($object->id > 0) +{ @@ -104,44 +93,54 @@ - print dol_get_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice'); - - $totalpaid = $object->getSommePaiement(); - - $linkback = ''.$langs->trans("BackToList").''; - - $morehtmlref = '
'; - // Ref supplier - $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1); - // Thirdparty - $morehtmlref .= '
'.$object->thirdparty->getNomUrl(1); - if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) { - $morehtmlref .= ' '; - } - // Project - if (isModEnabled('project')) { - $langs->load("projects"); - $morehtmlref .= '
'; - if (0) { - $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); - if ($action != 'classify') { - $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; - } - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); - } else { - if (!empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref .= $proj->getNomUrl(1); - if ($proj->title) { - $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; - } - } - } - } - $morehtmlref .= '
'; - - $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status - - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0); - - print '
'; - print '
'; + dol_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), -1, 'bill'); + + $totalpaye = $object->getSommePaiement(); + + $linkback = ''.$langs->trans("BackToList").''; + + $morehtmlref = '
'; + // Ref supplier + $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); + if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' ('.$langs->trans("OtherBills").')'; + // Project + if (!empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref .= '
'.$langs->trans('Project').' '; + if ($user->rights->facture->creer) + { + if ($action != 'classify') + //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + $morehtmlref .= ' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref .= ''; + $morehtmlref .= ''; + } else { + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (!empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref .= ''; + $morehtmlref .= $proj->ref; + $morehtmlref .= ''; + } else { + $morehtmlref .= ''; + } + } + } + $morehtmlref .= '
'; + + $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0); + + print '
'; + print '
'; @@ -150 +149 @@ - $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1); + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); @@ -152 +151,2 @@ - foreach ($filearray as $key => $file) { + foreach ($filearray as $key => $file) + { @@ -159 +159,2 @@ - if ($action == 'delete') { + if ($action == 'delete') + { @@ -167 +167,0 @@ - print ''; @@ -169,2 +169,2 @@ - print ''; - if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) { + if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) + { @@ -175 +175,2 @@ - if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) { + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) + { @@ -182,3 +183,8 @@ - if (count($facidavoir) > 0) { - $invoicecredits = array(); - foreach ($facidavoir as $facid) { + if (count($facidavoir) > 0) + { + print ' ('.$langs->transnoentities("InvoiceHasAvoir"); + $i = 0; + foreach ($facidavoir as $id) + { + if ($i == 0) print ' '; + else print ','; @@ -186,2 +192,2 @@ - $facavoir->fetch($facid); - $invoicecredits[] = $facavoir->getNomUrl(1); + $facavoir->fetch($id); + print $facavoir->getNomUrl(1); @@ -189 +195 @@ - print ' ('.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits) . ')'; + print ')'; @@ -192,2 +198,3 @@ - if ($facidnext > 0) { - $facthatreplace = new FactureFournisseur($db); + if ($facidnext > 0) + { + $facthatreplace=new FactureFournisseur($db); @@ -211,2 +218,3 @@ - if ($mysoc->localtax1_assuj == "1") { //Localtax1 - print '
'; + if ($societe->localtax1_assuj == "1") //Localtax1 + { + print ''; @@ -216,2 +224,3 @@ - if ($mysoc->localtax2_assuj == "1") { //Localtax2 - print ''; + if ($societe->localtax2_assuj == "1") //Localtax2 + { + print ''; @@ -239 +248 @@ - print dol_get_fiche_end(); + dol_fiche_end(); @@ -243,2 +252,2 @@ - $permission = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); - $permtoedit = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); + $permission = $user->rights->fournisseur->facture->creer; + $permtoedit = $user->rights->fournisseur->facture->creer; @@ -246,21 +255,5 @@ - - $defaulttpldir = '/core/tpl'; - $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir)); - foreach ($dirtpls as $module => $reldir) { - if (!empty($module)) { - $tpl = dol_buildpath($reldir.'/document_actions_post_headers.tpl.php'); - } else { - $tpl = DOL_DOCUMENT_ROOT.$reldir.'/document_actions_post_headers.tpl.php'; - } - - if (empty($conf->file->strict_mode)) { - $res = @include $tpl; - } else { - $res = include $tpl; // for debug - } - if ($res) { - break; - } - } -} else { - print $langs->trans('ErrorUnknown'); + include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; +} +else +{ + print $langs->trans('ErrorUnknown'); --- /tmp/dsg/dolibarr/htdocs/fourn/facture/github_19.0.3_impayees.php +++ /tmp/dsg/dolibarr/htdocs/fourn/facture/client_impayees.php @@ -0,0 +1,302 @@ + + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2012 Vinicius Nogueira + * Copyright (C) 2012 Juanjo Menent + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/fourn/facture/impayees.php + * \ingroup facture + * \brief Page to list all unpaid invoices + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; + +if (!$user->rights->fournisseur->facture->lire) accessforbidden(); + +$langs->loadLangs(array("companies", "bills")); + +$socid = GETPOST('socid', 'int'); +$option = GETPOST('option'); + +// Security check +if ($user->socid > 0) +{ + $action = ''; + $socid = $user->socid; +} + +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); + +$search_ref = GETPOST('search_ref', 'alpha'); +$search_ref_supplier = GETPOST('search_ref_supplier', 'alpha'); +$search_company = GETPOST('search_company', 'alpha'); +$search_amount_no_tax = GETPOST('search_amount_no_tax', 'alpha'); +$search_amount_all_tax = GETPOST('search_amount_all_tax', 'alpha'); + +$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; +$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (!$sortfield) $sortfield = "f.date_lim_reglement"; +if (!$sortorder) $sortorder = "ASC"; + +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers +{ + $search_ref = ""; + $search_ref_supplier = ""; + $search_company = ""; + $search_amount_no_tax = ""; + $search_amount_all_tax = ""; +} + +/* + * View + */ + +$now = dol_now(); + +llxHeader('', $langs->trans("BillsSuppliersUnpaid")); + +$title = $langs->trans("BillsSuppliersUnpaid"); + +$facturestatic = new FactureFournisseur($db); +$companystatic = new Societe($db); + +if ($user->rights->fournisseur->facture->lire) +{ + $sql = "SELECT s.rowid as socid, s.nom as name,"; + $sql .= " f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc,"; + $sql .= " f.datef as df, f.date_lim_reglement as datelimite, "; + $sql .= " f.paye as paye, f.rowid as facid, f.fk_statut"; + $sql .= " ,sum(pf.amount) as am"; + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user "; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ",".MAIN_DB_PREFIX."facture_fourn as f"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn "; + $sql .= " WHERE f.entity = ".$conf->entity; + $sql .= " AND f.fk_soc = s.rowid"; + $sql .= " AND f.paye = 0 AND f.fk_statut = 1"; + if ($option == 'late') $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'"; + if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + if ($socid) $sql .= " AND s.rowid = ".$socid; + + if (GETPOST('filtre')) + { + $filtrearr = explode(",", GETPOST('filtre')); + foreach ($filtrearr as $fil) + { + $filt = explode(":", $fil); + $sql .= " AND ".$filt[0]." = ".$filt[1]; + } + } + + if ($search_ref) + { + $sql .= " AND f.ref LIKE '%".$search_ref."%'"; + } + if ($search_ref_supplier) + { + $sql .= " AND f.ref_supplier LIKE '%".$search_ref_supplier."%'"; + } + + if ($search_company) + { + $sql .= " AND s.nom LIKE '%".$search_company."%'"; + } + + if ($search_amount_no_tax) + { + $sql .= " AND f.total_ht = '".$search_amount_no_tax."'"; + } + + if ($search_amount_all_tax) + { + $sql .= " AND f.total_ttc = '".$search_amount_all_tax."'"; + } + + if (dol_strlen(GETPOST('sf_re')) > 0) + { + $sql .= " AND f.ref_supplier LIKE '%".$db->escape(GETPOST('sf_re'))."%'"; + } + + $sql .= " GROUP BY s.rowid, s.nom, f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.datef, f.date_lim_reglement, f.paye, f.fk_statut"; + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user "; + $sql .= $db->order($sortfield, $sortorder); + if (!in_array("f.ref_supplier", explode(',', $sortfield))) $sql .= ", f.ref_supplier DESC"; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + + if ($socid) + { + $soc = new Societe($db); + $soc->fetch($socid); + } + + $param = ''; + if ($socid) $param .= "&socid=".$socid; + + if ($search_ref) $param .= '&search_ref='.urlencode($search_ref); + if ($search_ref_supplier) $param .= '&search_ref_supplier='.urlencode($search_ref_supplier); + if ($search_company) $param .= '&search_company='.urlencode($search_company); + if ($search_amount_no_tax) $param .= '&search_amount_no_tax='.urlencode($search_amount_no_tax); + if ($search_amount_all_tax) $param .= '&search_amount_all_tax='.urlencode($search_amount_all_tax); + + $param .= ($option ? "&option=".$option : ""); + if (!empty($late)) $param .= '&late='.urlencode($late); + $urlsource = str_replace('&', '&', $param); + + $titre = ($socid ? $langs->trans("BillsSuppliersUnpaidForCompany", $soc->name) : $langs->trans("BillsSuppliersUnpaid")); + + if ($option == 'late') $titre .= ' ('.$langs->trans("Late").')'; + else $titre .= ' ('.$langs->trans("All").')'; + + $link = ''; + if (empty($option)) $link = ''.$langs->trans("ShowUnpaidLateOnly").''; + elseif ($option == 'late') $link = ''.$langs->trans("ShowUnpaidAll").''; + print load_fiche_titre($titre, $link); + + print_barre_liste('', '', $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', 0); // We don't want pagination on this page + $i = 0; + print '
'; + + print '
'.$langs->trans('AmountHT').''.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->trans('AmountVAT').''.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->trans('AmountHT').''.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->trans('AmountVAT').''.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->transcountry("AmountLT1", $societe->country_code).''.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->transcountry("AmountLT2", $societe->country_code).''.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'
'.$langs->transcountry("AmountLT1", $mysoc->country_code).'
'.$langs->transcountry("AmountLT1", $societe->country_code).'
'.$langs->transcountry("AmountLT2", $mysoc->country_code).'
'.$langs->transcountry("AmountLT2", $societe->country_code).'
'; + print ''; + print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "f.rowid", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("RefSupplier", $_SERVER["PHP_SELF"], "f.ref_supplier", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "f.datef", "", $param, '', $sortfield, $sortorder, 'center '); + print_liste_field_titre("DateDue", $_SERVER["PHP_SELF"], "f.date_lim_reglement", "", $param, '', $sortfield, $sortorder, 'center '); + print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "f.total_ht", "", $param, '', $sortfield, $sortorder, 'right '); + print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], "f.total_ttc", "", $param, '', $sortfield, $sortorder, 'right '); + print_liste_field_titre("AlreadyPaid", $_SERVER["PHP_SELF"], "am", "", $param, '', $sortfield, $sortorder, 'right '); + print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "fk_statut,paye,am", "", $param, '', $sortfield, $sortorder, 'right '); + print "\n"; + + // Lines with filter fields + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + if ($num > 0) + { + $total_ht = 0; + $total_ttc = 0; + $total_paid = 0; + + while ($i < $num) + { + $objp = $db->fetch_object($resql); + + $facturestatic->statut = $objp->fk_statut; + $facturestatic->date_echeance = $db->jdate($objp->datelimite); + + + + print ''; + $classname = "impayee"; + + print '\n"; + + print ''; + + print '\n"; + print '\n"; + + print ''; + + print ""; + print ""; + print ""; + + // Show invoice status + print ''; + + print "\n"; + $total_ht += $objp->total_ht; + $total_ttc += $objp->total_ttc; + $total_paid += $objp->am; + + $i++; + } + + print ''; + print ""; + print ""; + print ""; + print ""; + print ''; + print "\n"; + } + + print "
'; + print ''; + print '  '; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $searchpicto = $form->showFilterAndCheckAddButtons(0); + print $searchpicto; + print '
'; + $facturestatic->id = $objp->facid; + $facturestatic->ref = $objp->ref; + print $facturestatic->getNomUrl(1); + print "'.dol_trunc($objp->ref_supplier, 12).''.dol_print_date($db->jdate($objp->df), 'day')."'.dol_print_date($db->jdate($objp->datelimite), 'day'); + if ($facturestatic->hasDelay()) { + print img_warning($langs->trans("Late")); + } + print "'; + $companystatic->id = $objp->socid; + $companystatic->name = $objp->name; + print $companystatic->getNomUrl(1, 'supplier', 32); + print '".price($objp->total_ht)."".price($objp->total_ttc)."".price($objp->am)."'; + print $facturestatic->LibStatut($objp->paye, $objp->fk_statut, 5, $objp->am); + print '
".$langs->trans("Total").": ".price($total_ht)."".price($total_ttc)."".price($total_paid)." 
"; + + print ''; + + $db->free($resql); + } + else + { + dol_print_error($db); + } +} + +// End of page +llxFooter(); +$db->close(); --- /tmp/dsg/dolibarr/htdocs/fourn/facture/github_19.0.3_info.php +++ /tmp/dsg/dolibarr/htdocs/fourn/facture/client_info.php @@ -28 +27,0 @@ -// Load Dolibarr environment @@ -34 +33 @@ -if (isModEnabled('project')) { +if (!empty($conf->projet->enabled)) { @@ -40 +39 @@ -$id = GETPOST("facid", 'int') ? GETPOST("facid", 'int') : GETPOST("id", 'int'); +$id = GETPOST("facid", 'int') ?GETPOST("facid", 'int') : GETPOST("id", 'int'); @@ -44,3 +43 @@ -if ($user->socid) { - $socid = $user->socid; -} +if ($user->socid) $socid = $user->socid; @@ -48 +44,0 @@ -$hookmanager->initHooks(array('invoicesuppliercardinfo')); @@ -51,3 +46,0 @@ - -$usercancreate = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); -$permissiontoadd = $usercancreate; @@ -61,4 +53,0 @@ -$object->fetch($id, $ref); -$object->fetch_thirdparty(); -$object->info($object->id); -$alreadypaid = $object->getSommePaiement(); @@ -66 +55 @@ -$title = $object->ref." - ".$langs->trans('Info'); +$title = $langs->trans('SupplierInvoice')." - ".$langs->trans('Info'); @@ -69,0 +59,7 @@ +$object->fetch($id, $ref); +$object->fetch_thirdparty(); + +$object->info($object->id); + +$alreadypaid = $object->getSommePaiement(); + @@ -72 +68 @@ -print dol_get_fiche_head($head, 'info', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice'); +dol_fiche_head($head, 'info', $langs->trans('SupplierInvoice'), -1, 'bill'); @@ -74 +70 @@ -$linkback = ''.$langs->trans("BackToList").''; +$linkback = ''.$langs->trans("BackToList").''; @@ -81,4 +77,2 @@ -$morehtmlref .= '
'.$object->thirdparty->getNomUrl(1); -if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) { - $morehtmlref .= ' '; -} +$morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); +if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' ('.$langs->trans("OtherBills").')'; @@ -86,19 +80,31 @@ -if (isModEnabled('project')) { - $langs->load("projects"); - $morehtmlref .= '
'; - if (0) { - $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); - if ($action != 'classify') { - $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; - } - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); - } else { - if (!empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref .= $proj->getNomUrl(1); - if ($proj->title) { - $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; - } - } - } +if (!empty($conf->projet->enabled)) +{ + $langs->load("projects"); + $morehtmlref .= '
'.$langs->trans('Project').' '; + if ($user->rights->facture->creer) + { + if ($action != 'classify') + //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + $morehtmlref .= ' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref .= ''; + $morehtmlref .= '
'; + } else { + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (!empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref .= ''; + $morehtmlref .= $proj->ref; + $morehtmlref .= ''; + } else { + $morehtmlref .= ''; + } + } @@ -108 +114 @@ -$object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status +$object->totalpaye = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status --- /tmp/dsg/dolibarr/htdocs/fourn/facture/github_19.0.3_list.php +++ /tmp/dsg/dolibarr/htdocs/fourn/facture/client_list.php @@ -2,15 +2,13 @@ -/* Copyright (C) 2002-2006 Rodolphe Quiedeville - * Copyright (C) 2004-2019 Laurent Destailleur - * Copyright (C) 2005-2013 Regis Houssin - * Copyright (C) 2013-2019 Philippe Grand - * Copyright (C) 2013 Florian Henry - * Copyright (C) 2013 Cédric Salvador - * Copyright (C) 2015 Marcos García - * Copyright (C) 2015-2007 Juanjo Menent - * Copyright (C) 2015 Abbes Bahfir - * Copyright (C) 2015-2016 Ferran Marcet - * Copyright (C) 2017 Josep Lluís Amador - * Copyright (C) 2018-2022 Charlene Benke - * Copyright (C) 2018-2020 Frédéric France - * Copyright (C) 2019-2021 Alexandre Spangaro - * Copyright (C) 2023 Nick Fragoulis +/* Copyright (C) 2002-2006 Rodolphe Quiedeville + * Copyright (C) 2004-2019 Laurent Destailleur + * Copyright (C) 2005-2013 Regis Houssin + * Copyright (C) 2013-2019 Philippe Grand + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2013 Cédric Salvador + * Copyright (C) 2015 Marcos García + * Copyright (C) 2015-2007 Juanjo Menent + * Copyright (C) 2015 Abbes Bahfir + * Copyright (C) 2015-2016 Ferran Marcet + * Copyright (C) 2017 Josep Lluís Amador + * Copyright (C) 2018 Charlene Benke + * Copyright (C) 2018-2019 Frédéric France @@ -38 +35,0 @@ -// Load Dolibarr environment @@ -49 +46,2 @@ -require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; + +if (!$user->rights->fournisseur->facture->lire) accessforbidden(); @@ -54 +52 @@ -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); @@ -60,4 +58,15 @@ -$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'supplierinvoicelist'; -$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...) - -$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); +$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'supplierinvoicelist'; + +$socid = GETPOST('socid', 'int'); + +// Security check +if ($user->socid > 0) +{ + $action = ''; + $_GET["action"] = ''; + $socid = $user->socid; +} + +$mode = GETPOST("mode"); + +$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); @@ -67 +76,2 @@ -$search_ref = GETPOST('sf_ref') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha'); +$search_product_category = GETPOST('search_product_category', 'int'); +$search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha'); @@ -70 +79,0 @@ -$search_subtype = GETPOST('search_subtype', 'int'); @@ -73 +81,0 @@ -$search_company_alias = GETPOST('search_company_alias', 'alpha'); @@ -87 +94,0 @@ -$search_paymentcond = GETPOST('search_paymentcond', 'int'); @@ -90 +97 @@ -$search_state = GETPOST("search_state"); +$search_state = trim(GETPOST("search_state")); @@ -95,10 +102,7 @@ -$search_date_start = GETPOSTDATE('search_date_start', '', 'tzserver'); -$search_date_end = GETPOSTDATE('search_date_end', '23:59:59', 'tzserver'); -$search_datelimit_startday = GETPOST('search_datelimit_startday', 'int'); -$search_datelimit_startmonth = GETPOST('search_datelimit_startmonth', 'int'); -$search_datelimit_startyear = GETPOST('search_datelimit_startyear', 'int'); -$search_datelimit_endday = GETPOST('search_datelimit_endday', 'int'); -$search_datelimit_endmonth = GETPOST('search_datelimit_endmonth', 'int'); -$search_datelimit_endyear = GETPOST('search_datelimit_endyear', 'int'); -$search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear); -$search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear); +$day = GETPOST('day', 'int'); +$month = GETPOST('month', 'int'); +$year = GETPOST('year', 'int'); +$day_lim = GETPOST('day_lim', 'int'); +$month_lim = GETPOST('month_lim', 'int'); +$year_lim = GETPOST('year_lim', 'int'); +$toselect = GETPOST('toselect', 'array'); @@ -107,4 +111,2 @@ -$search_categ_sup = trim(GETPOST("search_categ_sup", 'int')); -$search_product_category = GETPOST('search_product_category', 'int'); - -$option = GETPOST('search_option'); + +$option = GETPOST('option'); @@ -116,4 +118,3 @@ -// Load variable for pagination -$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); @@ -121,4 +122 @@ -if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { - // If $page is not defined, or '' or -1 or if we click on clear filters - $page = 0; -} +if ($page == -1 || $page == null || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) { $page = 0; } @@ -126,6 +123,0 @@ -if (!$sortorder) { - $sortorder = "DESC"; -} -if (!$sortfield) { - $sortfield = "f.datef,f.rowid"; -} @@ -134,9 +126,2 @@ - -$socid = GETPOST('socid', 'int'); - -// Security check -if ($user->socid > 0) { - $action = ''; - $_GET["action"] = ''; - $socid = $user->socid; -} +if (!$sortorder) $sortorder = "DESC"; +if (!$sortfield) $sortfield = "f.datef,f.rowid"; @@ -153 +138 @@ -// Fetch optionals attributes and labels +// fetch optionals attributes and labels @@ -161,0 +147,2 @@ + 'pd.description'=>'Description', + 's.nom'=>"ThirdParty", @@ -163,3 +149,0 @@ - 's.nom'=>"ThirdParty", - 's.code_fournisseur'=>"SupplierCodeShort", - 'pd.description'=>'Description', @@ -167,3 +151 @@ -if (empty($user->socid)) { - $fieldstosearchall["f.note_private"] = "NotePrivate"; -} +if (empty($user->socid)) $fieldstosearchall["f.note_private"] = "NotePrivate"; @@ -173,36 +155,32 @@ - 'f.ref'=>array('label'=>"Ref", 'checked'=>1), - 'f.ref_supplier'=>array('label'=>"RefSupplier", 'checked'=>1), - 'f.type'=>array('label'=>"Type", 'checked'=>0), - 'f.subtype'=>array('label'=>"InvoiceSubtype", 'checked'=>0,), - 'f.label'=>array('label'=>"Label", 'checked'=>0), - 'f.datef'=>array('label'=>"DateInvoice", 'checked'=>1), - 'f.date_lim_reglement'=>array('label'=>"DateDue", 'checked'=>1), - 'p.ref'=>array('label'=>"ProjectRef", 'checked'=>0), - 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1, 'position'=>41), - 's.name_alias'=>array('label'=>"AliasNameShort", 'checked'=>0, 'position'=>42), - 's.town'=>array('label'=>"Town", 'checked'=>-1, 'position'=>43), - 's.zip'=>array('label'=>"Zip", 'checked'=>1, 'position'=>44), - 'state.nom'=>array('label'=>"StateShort", 'checked'=>0, 'position'=>45), - 'country.code_iso'=>array('label'=>"Country", 'checked'=>0, 'position'=>46), - 'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers, 'position'=>49), - 'f.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>1, 'position'=>52), - 'f.fk_cond_reglement'=>array('label'=>"PaymentConditionsShort", 'checked'=>1, 'position'=>50), - 'f.total_ht'=>array('label'=>"AmountHT", 'checked'=>1, 'position'=>105), - 'f.total_vat'=>array('label'=>"AmountVAT", 'checked'=>0, 'position'=>110), - 'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax1_assuj == "1", 'position'=>95), - 'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax2_assuj == "1", 'position'=>100), - 'f.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0, 'position'=>115), - 'dynamount_payed'=>array('label'=>"Paid", 'checked'=>0, 'position'=>116), - 'rtp'=>array('label'=>"Rest", 'checked'=>0, 'position'=>117), - 'f.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'position'=>205, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)), - 'f.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'position'=>206, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)), - 'f.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'position'=>207, 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)), - 'f.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'position'=>208, 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)), - 'f.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'position'=>209, 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)), - 'multicurrency_dynamount_payed'=>array('label'=>'MulticurrencyAlreadyPaid', 'position'=>210, 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)), - 'multicurrency_rtp'=>array('label'=>'MulticurrencyRemainderToPay', 'checked'=>0, 'position'=>211, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)), // Not enabled by default because slow - 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>500), - 'f.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>501), - 'f.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>502), - 'f.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000), - 'f.nb_docs'=>array('label'=>"Documents", 'checked'=>1, 'position'=>510), + 'f.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), + 'f.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1), + 'f.type'=>array('label'=>$langs->trans("Type"), 'checked'=>0), + 'f.label'=>array('label'=>$langs->trans("Label"), 'checked'=>0), + 'f.datef'=>array('label'=>$langs->trans("DateInvoice"), 'checked'=>1), + 'f.date_lim_reglement'=>array('label'=>$langs->trans("DateDue"), 'checked'=>1), + 'p.ref'=>array('label'=>$langs->trans("ProjectRef"), 'checked'=>0), + 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1), + 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1), + 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1), + 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0), + 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0), + 'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers), + 'f.fk_mode_reglement'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>1), + 'f.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1), + 'f.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0), + 'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax1_assuj == "1"), + 'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax2_assuj == "1"), + 'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0), + 'u.login'=>array('label'=>"Author", 'checked'=>1), + 'dynamount_payed'=>array('label'=>$langs->trans("Payed"), 'checked'=>0), + 'rtp'=>array('label'=>$langs->trans("Rest"), 'checked'=>0), + 'f.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), + 'f.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), + 'f.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), + 'f.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), + 'f.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), + 'multicurrency_dynamount_payed'=>array('label'=>'MulticurrencyAlreadyPaid', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), + 'multicurrency_rtp'=>array('label'=>'MulticurrencyRemainderToPay', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), // Not enabled by default because slow + 'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), + 'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), + 'f.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), @@ -211,2 +189,8 @@ -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; - +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) +{ + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) + { + if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) + $arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])); + } +} @@ -215,16 +198,0 @@ - -if (!isModEnabled('supplier_invoice')) { - accessforbidden(); -} -if ((!$user->hasRight("fournisseur", "facture", "lire") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) - || (!$user->hasRight("supplier_invoice", "lire") && getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD'))) { - accessforbidden(); -} - -if (!$user->hasRight('societe', 'client', 'voir')) { - $search_sale = $user->id; -} - -$permissiontoread = ($user->hasRight("fournisseur", "facture", "lire") || $user->hasRight("supplier_invoice", "lire")); -$permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); -$permissiontodelete = ($user->hasRight("fournisseur", "facture", "supprimer") || $user->hasRight("supplier_invoice", "supprimer")); @@ -237,9 +205,4 @@ -if (GETPOST('cancel', 'alpha')) { - $action = 'list'; - $massaction = ''; -} -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { - $massaction = ''; -} - -$parameters = array('socid'=>$socid, 'arrayfields'=>&$arrayfields); +if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction = ''; } + +$parameters = array('socid'=>$socid); @@ -247,6 +210,4 @@ -if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -} - -if (empty($reshook)) { - // Selection of new fields +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if (empty($reshook)) +{ @@ -255,2 +216,2 @@ - // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha')) { // All tests must be present to be compatible with all browsers + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha')) // All tests must be present to be compatible with all browsers + { @@ -264 +224,0 @@ - $search_subtype = ''; @@ -268 +227,0 @@ - $search_company_alias = ""; @@ -284 +242,0 @@ - $search_paymentcond = ''; @@ -287,0 +246 @@ + $search_type = ''; @@ -290,11 +249,7 @@ - $search_date_start = ''; - $search_date_end = ''; - $search_datelimit_startday = ''; - $search_datelimit_startmonth = ''; - $search_datelimit_startyear = ''; - $search_datelimit_endday = ''; - $search_datelimit_endmonth = ''; - $search_datelimit_endyear = ''; - $search_datelimit_start = ''; - $search_datelimit_end = ''; - $toselect = array(); + $year = ""; + $month = ""; + $day = ""; + $year_lim = ""; + $month_lim = ""; + $day_lim = ""; + $toselect = ''; @@ -302 +256,0 @@ - $search_categ_sup = 0; @@ -310,0 +265,3 @@ + $permissiontoread = $user->rights->fournisseur->facture->lire; + $permissiontoadd = $user->rights->fournisseur->facture->creer; + $permissiontodelete = $user->rights->fournisseur->facture->supprimer; @@ -313,80 +269,0 @@ - - if ($massaction == 'banktransfertrequest') { - $langs->load("withdrawals"); - - if (!$user->hasRight("paymentbybanktransfer", "create")) { - $error++; - setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); - } else { - //Checking error - $error = 0; - - $arrayofselected = is_array($toselect) ? $toselect : array(); - $listofbills = array(); - foreach ($arrayofselected as $toselectid) { - $objecttmp = new FactureFournisseur($db); - $result = $objecttmp->fetch($toselectid); - if ($result > 0) { - $totalpaid = $objecttmp->getSommePaiement(); - $totalcreditnotes = $objecttmp->getSumCreditNotesUsed(); - $totaldeposits = $objecttmp->getSumDepositsUsed(); - $objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT'); - if ($objecttmp->statut == FactureFournisseur::STATUS_DRAFT) { - $error++; - setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors'); - } elseif ($objecttmp->paye || $objecttmp->resteapayer == 0) { - $error++; - setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors'); - } elseif ($objecttmp->resteapayer < 0) { - $error++; - setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors'); - } - - $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande"; - $rsql .= " , pfd.date_traite as date_traite"; - $rsql .= " , pfd.amount"; - $rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login"; - $rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd"; - $rsql .= " , ".MAIN_DB_PREFIX."user as u"; - $rsql .= " WHERE fk_facture_fourn = ".((int) $objecttmp->id); - $rsql .= " AND pfd.fk_user_demande = u.rowid"; - $rsql .= " AND pfd.traite = 0"; - $rsql .= " ORDER BY pfd.date_demande DESC"; - - $result_sql = $db->query($rsql); - if ($result_sql) { - $numprlv = $db->num_rows($result_sql); - } - - if ($numprlv > 0) { - $error++; - setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'warnings'); - } elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'VIR') { - $error++; - setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors'); - } else { - $listofbills[] = $objecttmp; // $listofbills will only contains invoices with good payment method and no request already done - } - } - } - - // Massive withdraw request for request with no errors - if (!empty($listofbills)) { - $nbwithdrawrequestok = 0; - foreach ($listofbills as $aBill) { - $db->begin(); - $result = $aBill->demande_prelevement($user, $aBill->resteapayer, 'bank-transfer', 'supplier_invoice'); - if ($result > 0) { - $db->commit(); - $nbwithdrawrequestok++; - } else { - $db->rollback(); - setEventMessages($aBill->error, $aBill->errors, 'errors'); - } - } - if ($nbwithdrawrequestok > 0) { - setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs'); - } - } - } - } @@ -407,16 +284,3 @@ -$subtypearray = $object->getArrayOfInvoiceSubtypes(0); -$now = dol_now(); - -if ($socid > 0) { - $soc = new Societe($db); - $soc->fetch($socid); - if (empty($search_company)) { - $search_company = $soc->name; - } -} - -$title = $langs->trans("BillsSuppliers").($socid ? ' - '.$soc->name : ''); -$help_url = 'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores'; - -// Build and execute select -// -------------------------------------------------------------------- + +// llxHeader('',$langs->trans("SuppliersInvoices"),'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores'); + @@ -424,5 +288,3 @@ -if ($search_all) { - $sql = 'SELECT DISTINCT'; -} -$sql .= " f.rowid as facid, f.ref, f.ref_supplier, f.type, f.subtype, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement, f.fk_cond_reglement,"; -$sql .= " f.total_ht, f.total_ttc, f.total_tva as total_vat, f.paye as paye, f.close_code, f.fk_statut as fk_statut, f.libelle as label, f.datec as date_creation, f.tms as date_update,"; +if ($search_all || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +$sql .= " f.rowid as facid, f.ref, f.ref_supplier, f.type, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement,"; +$sql .= " f.total_ht, f.total_ttc, f.total_tva as total_vat, f.paye as paye, f.fk_statut as fk_statut, f.libelle as label, f.datec as date_creation, f.tms as date_update,"; @@ -433 +295 @@ -$sql .= " s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur,"; +$sql .= " s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur,"; @@ -438 +300,4 @@ -$sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender'; +$sql .= " u.login"; +// We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0) +// TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field. +if (!$search_all) $sql .= ', SUM(pf.amount) as dynamount_payed'; @@ -441,3 +306 @@ - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { - $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : ''); - } + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); @@ -447 +310 @@ -$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook @@ -449,10 +311,0 @@ -$sql = preg_replace('/,\s*$/', '', $sql); - -// We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0) -// TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field. -if (!$search_all) { - $sql .= ', SUM(pf.amount) as dynamount_payed'; -} - -$sqlfields = $sql; // $sql fields to remove for count total - @@ -464,10 +317,4 @@ -if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)"; -} -if (!$search_all) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; -} -if ($search_all) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as pd ON f.rowid=pd.fk_facture_fourn'; -} -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid'; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)"; +if (!$search_all) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; +if ($search_all || $search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as pd ON f.rowid=pd.fk_facture_fourn'; +if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; @@ -475 +322,4 @@ -if ($search_user > 0) { +// We'll need this table joined to the select in order to filter by sale +if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +if ($search_user > 0) +{ @@ -479,4 +329 @@ -// Add table from hooks -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; +$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid'; @@ -485,29 +332,16 @@ -if ($socid > 0) { - $sql .= ' AND s.rowid = '.((int) $socid); -} -if ($search_ref) { - if (is_numeric($search_ref)) { - $sql .= natural_search(array('f.ref'), $search_ref); - } else { - $sql .= natural_search('f.ref', $search_ref); - } -} -if ($search_ref) { - $sql .= natural_search('f.ref', $search_ref); -} -if ($search_refsupplier) { - $sql .= natural_search('f.ref_supplier', $search_refsupplier); -} -if ($search_type != '' && $search_type >= 0) { - if ($search_type == '0') { - $sql .= " AND f.type = 0"; // standard - } - if ($search_type == '1') { - $sql .= " AND f.type = 1"; // replacement - } - if ($search_type == '2') { - $sql .= " AND f.type = 2"; // credit note - } - if ($search_type == '3') { - $sql .= " AND f.type = 3"; // deposit - } +if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category; +if ($socid > 0) $sql .= ' AND s.rowid = '.$socid; +if ($search_ref) +{ + if (is_numeric($search_ref)) $sql .= natural_search(array('f.ref'), $search_ref); + else $sql .= natural_search('f.ref', $search_ref); +} +if ($search_ref) $sql .= natural_search('f.ref', $search_ref); +if ($search_refsupplier) $sql .= natural_search('f.ref_supplier', $search_refsupplier); +if ($search_type != '' && $search_type >= 0) +{ + if ($search_type == '0') $sql .= " AND f.type = 0"; // standard + if ($search_type == '1') $sql .= " AND f.type = 1"; // replacement + if ($search_type == '2') $sql .= " AND f.type = 2"; // credit note + if ($search_type == '3') $sql .= " AND f.type = 3"; // deposit @@ -517,160 +351,30 @@ -if ($search_subtype != '' && $search_subtype != '-1') { - $sql .= " AND f.subtype IN (".$db->sanitize($db->escape($search_subtype)).")"; -} -if ($search_project) { - $sql .= natural_search('p.ref', $search_project); -} -if (empty($arrayfields['s.name_alias']['checked']) && $search_company) { - $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company); -} else { - if ($search_company) { - $sql .= natural_search('s.nom', $search_company); - } - if ($search_company_alias) { - $sql .= natural_search('s.name_alias', $search_company_alias); - } -} -if ($search_town) { - $sql .= natural_search('s.town', $search_town); -} -if ($search_zip) { - $sql .= natural_search("s.zip", $search_zip); -} -if ($search_state) { - $sql .= natural_search("state.nom", $search_state); -} -if ($search_country) { - $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')'; -} -if ($search_type_thirdparty != '' && $search_type_thirdparty >= 0) { - $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')'; -} -if ($search_montant_ht != '') { - $sql .= natural_search('f.total_ht', $search_montant_ht, 1); -} -if ($search_montant_vat != '') { - $sql .= natural_search('f.total_tva', $search_montant_vat, 1); -} -if ($search_montant_localtax1 != '') { - $sql .= natural_search('f.localtax1', $search_montant_localtax1, 1); -} -if ($search_montant_localtax2 != '') { - $sql .= natural_search('f.localtax2', $search_montant_localtax2, 1); -} -if ($search_montant_ttc != '') { - $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1); -} -if ($search_multicurrency_code != '') { - $sql .= " AND f.multicurrency_code = '".$db->escape($search_multicurrency_code)."'"; -} -if ($search_multicurrency_tx != '') { - $sql .= natural_search('f.multicurrency_tx', $search_multicurrency_tx, 1); -} -if ($search_multicurrency_montant_ht != '') { - $sql .= natural_search('f.multicurrency_total_ht', $search_multicurrency_montant_ht, 1); -} -if ($search_multicurrency_montant_vat != '') { - $sql .= natural_search('f.multicurrency_total_tva', $search_multicurrency_montant_vat, 1); -} -if ($search_multicurrency_montant_ttc != '') { - $sql .= natural_search('f.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1); -} -if ($search_login) { - $sql .= natural_search(array('u.login', 'u.lastname', 'u.firstname'), $search_login); -} -if ($search_status != '' && $search_status >= 0) { - $sql .= " AND f.fk_statut = ".((int) $search_status); -} -if ($search_paymentmode > 0) { - $sql .= " AND f.fk_mode_reglement = ".((int) $search_paymentmode); -} -if ($search_paymentcond > 0) { - $sql .= " AND f.fk_cond_reglement = ".((int) $search_paymentcond); -} -if ($search_date_start) { - $sql .= " AND f.datef >= '" . $db->idate($search_date_start) . "'"; -} -if ($search_date_end) { - $sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'"; -} -if ($search_datelimit_start) { - $sql .= " AND f.date_lim_reglement >= '" . $db->idate($search_datelimit_start) . "'"; -} -if ($search_datelimit_end) { - $sql .= " AND f.date_lim_reglement <= '" . $db->idate($search_datelimit_end) . "'"; -} -if ($option == 'late') { - $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'"; -} -if ($search_label) { - $sql .= natural_search('f.libelle', $search_label); -} -// Search on sale representative -if ($search_sale && $search_sale != '-1') { - if ($search_sale == -2) { - $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc)"; - } elseif ($search_sale > 0) { - $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; - } -} -$searchCategorySupplierList = $search_categ_sup ? array($search_categ_sup) : array(); -$searchCategorySupplierOperator = 0; -// Search for tag/category ($searchCategorySupplierList is an array of ID) -if (!empty($searchCategorySupplierList)) { - $searchCategorySupplierSqlList = array(); - $listofcategoryid = ''; - foreach ($searchCategorySupplierList as $searchCategorySupplier) { - if (intval($searchCategorySupplier) == -2) { - $searchCategorySupplierSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc)"; - } elseif (intval($searchCategorySupplier) > 0) { - if ($searchCategorySupplierOperator == 0) { - $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategorySupplier).")"; - } else { - $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplier); - } - } - } - if ($listofcategoryid) { - $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; - } - if ($searchCategorySupplierOperator == 1) { - if (!empty($searchCategorySupplierSqlList)) { - $sql .= " AND (".implode(' OR ', $searchCategorySupplierSqlList).")"; - } - } else { - if (!empty($searchCategorySupplierSqlList)) { - $sql .= " AND (".implode(' AND ', $searchCategorySupplierSqlList).")"; - } - } -} -// Search for tag/category ($searchCategoryProductList is an array of ID) -$searchCategoryProductList = $search_product_category ? array($search_product_category) : array(); -$searchCategoryProductOperator = 0; -if (!empty($searchCategoryProductList)) { - $searchCategoryProductSqlList = array(); - $listofcategoryid = ''; - foreach ($searchCategoryProductList as $searchCategoryProduct) { - if (intval($searchCategoryProduct) == -2) { - $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facture_fourn_det as fd WHERE fd.fk_facture_fourn = f.rowid AND fd.fk_product = ck.fk_product)"; - } elseif (intval($searchCategoryProduct) > 0) { - if ($searchCategoryProductOperator == 0) { - $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facture_fourn_det as fd WHERE fd.fk_facture_fourn = f.rowid AND fd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; - } else { - $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); - } - } - } - if ($listofcategoryid) { - $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facture_fourn_det as fd WHERE fd.fk_facture_fourn = f.rowid AND fd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; - } - if ($searchCategoryProductOperator == 1) { - if (!empty($searchCategoryProductSqlList)) { - $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")"; - } - } else { - if (!empty($searchCategoryProductSqlList)) { - $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; - } - } -} -if ($filter && $filter != -1) { +if ($search_project) $sql .= natural_search('p.ref', $search_project); +if ($search_company) $sql .= natural_search('s.nom', $search_company); +if ($search_town) $sql .= natural_search('s.town', $search_town); +if ($search_zip) $sql .= natural_search("s.zip", $search_zip); +if ($search_state) $sql .= natural_search("state.nom", $search_state); +if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')'; +if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')'; +if ($search_montant_ht != '') $sql .= natural_search('f.total_ht', $search_montant_ht, 1); +if ($search_montant_vat != '') $sql .= natural_search('f.total_tva', $search_montant_vat, 1); +if ($search_montant_localtax1 != '') $sql .= natural_search('f.localtax1', $search_montant_localtax1, 1); +if ($search_montant_localtax2 != '') $sql .= natural_search('f.localtax2', $search_montant_localtax2, 1); +if ($search_montant_ttc != '') $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1); +if ($search_multicurrency_code != '') $sql .= ' AND f.multicurrency_code = "'.$db->escape($search_multicurrency_code).'"'; +if ($search_multicurrency_tx != '') $sql .= natural_search('f.multicurrency_tx', $search_multicurrency_tx, 1); +if ($search_multicurrency_montant_ht != '') $sql .= natural_search('f.multicurrency_total_ht', $search_multicurrency_montant_ht, 1); +if ($search_multicurrency_montant_vat != '') $sql .= natural_search('f.multicurrency_total_tva', $search_multicurrency_montant_vat, 1); +if ($search_multicurrency_montant_ttc != '') $sql .= natural_search('f.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1); +if ($search_login) $sql .= natural_search('u.login', $search_login); +if ($search_status != '' && $search_status >= 0) $sql .= " AND f.fk_statut = ".$db->escape($search_status); +if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".$search_paymentmode.""; +$sql .= dolSqlDateFilter("f.datef", $day, $month, $year); +$sql .= dolSqlDateFilter("f.date_lim_reglement", $day_lim, $month_lim, $year_lim); +if ($option == 'late') $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'"; +if ($search_label) $sql .= natural_search('f.libelle', $search_label); +if ($search_status != '' && $search_status >= 0) +{ + $sql .= " AND f.fk_statut = ".$search_status; +} +if ($filter && $filter != -1) +{ @@ -678 +382,2 @@ - foreach ($aFilter as $fil) { + foreach ($aFilter as $fil) + { @@ -680,9 +385,7 @@ - $sql .= " AND ".$db->escape(trim($filt[0]))." = '".$db->escape(trim($filt[1]))."'"; - } -} -/* -if ($search_sale > 0) { - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale); -}*/ -if ($search_user > 0) { - $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='invoice_supplier' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".((int) $search_user); + $sql .= ' AND '.$db->escape(trim($filt[0])).' = '.$db->escape(trim($filt[1])); + } +} +if ($search_sale > 0) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$db->escape($search_sale); +if ($search_user > 0) +{ + $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='invoice_supplier' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".$search_user; @@ -694 +397 @@ -$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook @@ -697,3 +400,4 @@ -if (!$search_all) { - $sql .= " GROUP BY f.rowid, f.ref, f.ref_supplier, f.type, f.subtype, f.datef, f.date_lim_reglement, f.fk_mode_reglement, f.fk_cond_reglement,"; - $sql .= " f.total_ht, f.total_ttc, f.total_tva, f.paye, f.close_code, f.fk_statut, f.libelle, f.datec, f.tms,"; +if (!$search_all) +{ + $sql .= " GROUP BY f.rowid, f.ref, f.ref_supplier, f.type, f.datef, f.date_lim_reglement, f.fk_mode_reglement,"; + $sql .= " f.total_ht, f.total_ttc, f.total_tva, f.paye, f.fk_statut, f.libelle, f.datec, f.tms,"; @@ -701 +404,0 @@ - $sql .= ' f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,'; @@ -703,2 +406 @@ - $sql .= " f.fk_user_author,"; - $sql .= ' s.rowid, s.nom, s.name_alias, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,'; + $sql .= ' s.rowid, s.nom, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,'; @@ -709 +411 @@ - $sql .= " u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender"; + $sql .= " u.login"; @@ -716,5 +418,3 @@ - // Add GroupBy from hooks - $parameters = array('all' => $search_all, 'fieldstosearchall' => $fieldstosearchall); - $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - $sql .= $hookmanager->resPrint; -} else { +} +else +{ @@ -724,6 +424,2 @@ -// Add HAVING from hooks -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook -$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint; - -// Count total nb of records +$sql .= $db->order($sortfield, $sortorder); + @@ -731,15 +427,6 @@ -if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { - /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); - $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); - $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid/', '', $sqlforcount); - - $resql = $db->query($sqlforcount); - if ($resql) { - $objforcount = $db->fetch_object($resql); - $nbtotalofrecords = $objforcount->nbtotalofrecords; - } else { - dol_print_error($db); - } - - if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0 +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) +{ + $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); + if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 + { @@ -749,8 +436,3 @@ - $db->free($resql); -} - -// Complete request and execute it with limit -$sql .= $db->order($sortfield, $sortorder); -if ($limit) { - $sql .= $db->plimit($limit + 1, $offset); -} +} + +$sql .= $db->plimit($limit + 1, $offset); @@ -760,270 +442,169 @@ -if (!$resql) { - dol_print_error($db); - exit; -} - -$num = $db->num_rows($resql); - -// Direct jump if only one record found -if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) { - $obj = $db->fetch_object($resql); - $id = $obj->facid; - header("Location: ".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id); - exit; -} - -// Output page -// -------------------------------------------------------------------- - -llxHeader('', $title, $help_url); - -if ($socid) { - $soc = new Societe($db); - $soc->fetch($socid); - if (empty($search_company)) { - $search_company = $soc->name; - $search_company_alias = $soc->name_alias; - } -} - -$arrayofselected = is_array($toselect) ? $toselect : array(); - -$param = '&socid='.$socid; -if (!empty($mode)) { - $param .= '&mode='.urlencode($mode); -} -if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { - $param .= '&contextpage='.urlencode($contextpage); -} -if ($limit > 0 && $limit != $conf->liste_limit) { - $param .= '&limit='.((int) $limit); -} -if ($optioncss != '') { - $param .= '&optioncss='.urlencode($optioncss); -} -if ($search_all) { - $param .= '&search_all='.urlencode($search_all); -} -if ($search_date_start) { - $param .= buildParamDate('search_date_start', null, '', 'tzserver'); -} -if ($search_date_end) { - $param .= buildParamDate('search_date_end', null, '', 'tzserver'); -} -if ($search_datelimit_startday) { - $param .= '&search_datelimit_startday='.urlencode($search_datelimit_startday); -} -if ($search_datelimit_startmonth) { - $param .= '&search_datelimit_startmonth='.urlencode($search_datelimit_startmonth); -} -if ($search_datelimit_startyear) { - $param .= '&search_datelimit_startyear='.urlencode($search_datelimit_startyear); -} -if ($search_datelimit_endday) { - $param .= '&search_datelimit_endday='.urlencode($search_datelimit_endday); -} -if ($search_datelimit_endmonth) { - $param .= '&search_datelimit_endmonth='.urlencode($search_datelimit_endmonth); -} -if ($search_datelimit_endyear) { - $param .= '&search_datelimit_endyear='.urlencode($search_datelimit_endyear); -} -if ($search_ref) { - $param .= '&search_ref='.urlencode($search_ref); -} -if ($search_refsupplier) { - $param .= '&search_refsupplier='.urlencode($search_refsupplier); -} -if ($search_type != '') { - $param .= '&search_type='.urlencode($search_type); -} -if ($search_subtype != '') { - $param .= '&search_subtype='.urlencode($search_subtype); -} -if ($search_label) { - $param .= '&search_label='.urlencode($search_label); -} -if ($search_company) { - $param .= '&search_company='.urlencode($search_company); -} -if ($search_company_alias) { - $param .= '&search_company_alias='.urlencode($search_company_alias); -} -if ($search_login) { - $param .= '&search_login='.urlencode($search_login); -} -if ($search_montant_ht != '') { - $param .= '&search_montant_ht='.urlencode($search_montant_ht); -} -if ($search_montant_vat != '') { - $param .= '&search_montant_vat='.urlencode($search_montant_vat); -} -if ($search_montant_localtax1 != '') { - $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1); -} -if ($search_montant_localtax2 != '') { - $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2); -} -if ($search_montant_ttc != '') { - $param .= '&search_montant_ttc='.urlencode($search_montant_ttc); -} -if ($search_multicurrency_code != '') { - $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code); -} -if ($search_multicurrency_tx != '') { - $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx); -} -if ($search_multicurrency_montant_ht != '') { - $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht); -} -if ($search_multicurrency_montant_vat != '') { - $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat); -} -if ($search_multicurrency_montant_ttc != '') { - $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc); -} -if ($search_amount_no_tax) { - $param .= '&search_amount_no_tax='.urlencode($search_amount_no_tax); -} -if ($search_amount_all_tax) { - $param .= '&search_amount_all_tax='.urlencode($search_amount_all_tax); -} -if ($search_status >= 0) { - $param .= "&search_status=".urlencode($search_status); -} -if ($search_paymentmode) { - $param .= '&search_paymentmode='.urlencode($search_paymentmode); -} -if ($search_paymentcond) { - $param .= '&search_paymentcond='.urlencode($search_paymentcond); -} -if ($show_files) { - $param .= '&show_files='.urlencode($show_files); -} -if ($option) { - $param .= "&search_option=".urlencode($option); -} -if ($search_categ_sup > 0) { - $param .= '&search_categ_sup='.urlencode($search_categ_sup); -} -if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) { - $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty); -} - -// Add $param from extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; -// Add $param from hooks -$parameters = array('param' => &$param); -$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook -$param .= $hookmanager->resPrint; - -// List of mass actions available -$arrayofmassactions = array( - 'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"), - 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"), - //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), - //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), -); - -if (isModEnabled('paymentbybanktransfer') && $user->hasRight("paymentbybanktransfer", "create")) { - $langs->load('withdrawals'); - $arrayofmassactions['banktransfertrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeBankTransferOrder"); -} -if (!empty($permissiontodelete)) { - $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); -} -if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) { - $arrayofmassactions = array(); -} -$massactionbutton = $form->selectMassAction('', $arrayofmassactions); - -$url = DOL_URL_ROOT.'/fourn/facture/card.php?action=create'; -if (!empty($socid)) { - $url .= '&socid='.urlencode($socid); -} - -$i = 0; -print '
'."\n"; -if ($optioncss != '') { - print ''; -} -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; - -$newcardbutton = ''; -$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition')); -$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition')); -$newcardbutton .= dolGetButtonTitleSeparator(); -$newcardbutton .= dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))); - -print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_invoice', 0, $newcardbutton, '', $limit, 0, 0, 1); - -// Add code for pre mass action (confirmation or email presend form) -$topicmail = "SendBillRef"; -$modelmail = "invoice_supplier_send"; -$objecttmp = new FactureFournisseur($db); -$trackid = 'sinv'.$object->id; -include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; - -if ($search_all) { - $setupstring = ''; - foreach ($fieldstosearchall as $key => $val) { - $fieldstosearchall[$key] = $langs->trans($val); - $setupstring .= $key."=".$val.";"; - } - print ''."\n"; - print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; -} - -// If the user can view prospects other than his' -$moreforfilter = ''; -if ($user->hasRight("user", "user", "lire")) { - $langs->load("commercial"); - $moreforfilter .= '
'; - $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative'); - $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200'); - $moreforfilter .= '
'; -} -// If the user can view prospects other than his' -if ($user->hasRight("user", "user", "lire")) { - $moreforfilter .= '
'; - $tmptitle = $langs->trans('LinkedToSpecificUsers'); - $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); - $moreforfilter .= '
'; -} -// If the user can view prospects other than his' -if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) { - include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $moreforfilter .= '
'; - $tmptitle = $langs->trans('IncludingProductWithTag'); - $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); - $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth300 widthcentpercentminusx', 1); - $moreforfilter .= '
'; -} - -if (isModEnabled('categorie')) { - require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $moreforfilter .= '
'; - $tmptitle = $langs->trans('SuppliersCategoriesShort'); - $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1, $tmptitle); - $moreforfilter .= '
'; -} -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook -if (empty($reshook)) { - $moreforfilter .= $hookmanager->resPrint; -} else { - $moreforfilter = $hookmanager->resPrint; -} - -if (!empty($moreforfilter)) { - print '
'; - print $moreforfilter; +if ($resql) +{ + $num = $db->num_rows($resql); + + $arrayofselected = is_array($toselect) ? $toselect : array(); + + if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) + { + $obj = $db->fetch_object($resql); + $id = $obj->facid; + + header("Location: ".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id); + exit; + } + + llxHeader('', $langs->trans("SuppliersInvoices"), 'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores'); + + if ($socid) + { + $soc = new Societe($db); + $soc->fetch($socid); + if (empty($search_company)) $search_company = $soc->name; + } + + $param = '&socid='.$socid; + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); + if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); + if ($search_all) $param .= '&search_all='.urlencode($search_all); + if ($day) $param .= '&day='.urlencode($day); + if ($month) $param .= '&month='.urlencode($month); + if ($year) $param .= '&year='.urlencode($year); + if ($day_lim) $param .= '&day_lim='.urlencode($day_lim); + if ($month_lim) $param .= '&month_lim='.urlencode($month_lim); + if ($year_lim) $param .= '&year_lim='.urlencode($year_lim); + if ($search_ref) $param .= '&search_ref='.urlencode($search_ref); + if ($search_refsupplier) $param .= '&search_refsupplier='.urlencode($search_refsupplier); + if ($search_type != '') $param .= '&search_type='.urlencode($search_type); + if ($search_label) $param .= '&search_label='.urlencode($search_label); + if ($search_company) $param .= '&search_company='.urlencode($search_company); + if ($search_login) $param .= '&search_login='.urlencode($search_login); + if ($search_montant_ht != '') $param .= '&search_montant_ht='.urlencode($search_montant_ht); + if ($search_montant_vat != '') $param .= '&search_montant_vat='.urlencode($search_montant_vat); + if ($search_montant_localtax1 != '') $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1); + if ($search_montant_localtax2 != '') $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2); + if ($search_montant_ttc != '') $param .= '&search_montant_ttc='.urlencode($search_montant_ttc); + if ($search_multicurrency_code != '') $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code); + if ($search_multicurrency_tx != '') $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx); + if ($search_multicurrency_montant_ht != '') $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht); + if ($search_multicurrency_montant_vat != '') $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat); + if ($search_multicurrency_montant_ttc != '') $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc); + if ($search_amount_no_tax) $param .= '&search_amount_no_tax='.urlencode($search_amount_no_tax); + if ($search_amount_all_tax) $param .= '&search_amount_all_tax='.urlencode($search_amount_all_tax); + if ($search_status >= 0) $param .= "&search_status=".urlencode($search_status); + if ($show_files) $param .= '&show_files='.urlencode($show_files); + if ($option) $param .= "&option=".urlencode($option); + if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); + // Add $param from extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; + + // List of mass actions available + $arrayofmassactions = array( + 'validate'=>$langs->trans("Validate"), + 'generate_doc'=>$langs->trans("ReGeneratePDF"), + //'builddoc'=>$langs->trans("PDFMerge"), + //'presend'=>$langs->trans("SendByMail"), + ); + //if($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer"); + if ($user->rights->fournisseur->facture->supprimer) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); + if (in_array($massaction, array('presend', 'predelete', 'createbills'))) $arrayofmassactions = array(); + $massactionbutton = $form->selectMassAction('', $arrayofmassactions); + + $newcardbutton = ''; + if ($user->rights->fournisseur->facture->creer) + { + $newcardbutton .= dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/fourn/facture/card.php?action=create'); + } + + $i = 0; + print ''."\n"; + if ($optioncss != '') print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print_barre_liste($langs->trans("BillsSuppliers").($socid ? ' '.$soc->name : ''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_invoice', 0, $newcardbutton, '', $limit, 0, 0, 1); + + $topicmail = "SendBillRef"; + $modelmail = "invoice_supplier_send"; + $objecttmp = new FactureFournisseur($db); + $trackid = 'sinv'.$object->id; + include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; + + if ($massaction == 'createbills') + { + //var_dump($_REQUEST); + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + print $langs->trans('DateInvoice'); + print ''; + print $form->selectDate('', '', '', '', '', '', 1, 1); + print '
'; + print $langs->trans('CreateOneBillByThird'); + print ''; + print $form->selectyesno('createbills_onebythird', '', 1); + print '
'; + print $langs->trans('ValidateInvoices'); + print ''; + print $form->selectyesno('validate_invoices', 1, 1); + print '
'; + + print '
'; + print '
'; + print ' '; + print ''; + print '
'; + print '
'; + } + + if ($search_all) + { + foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); + print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'; + } + + // If the user can view prospects other than his' + $moreforfilter = ''; + if ($user->rights->societe->client->voir || $socid) + { + $langs->load("commercial"); + $moreforfilter .= '
'; + $moreforfilter .= $langs->trans('ThirdPartiesOfSaleRepresentative').': '; + $moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200'); + $moreforfilter .= '
'; + } + // If the user can view prospects other than his' + if ($user->rights->societe->client->voir || $socid) + { + $moreforfilter .= '
'; + $moreforfilter .= $langs->trans('LinkedToSpecificUsers').': '; + $moreforfilter .= $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); + $moreforfilter .= '
'; + } + // If the user can view prospects other than his' + if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire)) + { + include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + $moreforfilter .= '
'; + $moreforfilter .= $langs->trans('IncludingProductWithTag').': '; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); + $moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1); + $moreforfilter .= '
'; + } @@ -1031 +612,225 @@ - $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook + if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; + else $moreforfilter = $hookmanager->resPrint; + + if ($moreforfilter) + { + print '
'; + print $moreforfilter; + print '
'; + } + + $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; + $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); + + print '
'; + print ''."\n"; + + // Line for filters + print ''; + // Ref + if (!empty($arrayfields['f.ref']['checked'])) + { + print ''; + } + // Ref supplier + if (!empty($arrayfields['f.ref_supplier']['checked'])) + { + print ''; + } + // Type + if (!empty($arrayfields['f.type']['checked'])) + { + print ''; + } + // Label + if (!empty($arrayfields['f.label']['checked'])) + { + print ''; + } + // Date invoice + if (!empty($arrayfields['f.datef']['checked'])) + { + print ''; + } + // Date due + if (!empty($arrayfields['f.date_lim_reglement']['checked'])) + { + print ''; + } + // Project + if (!empty($arrayfields['p.ref']['checked'])) + { + print ''; + } + // Thirpdarty + if (!empty($arrayfields['s.nom']['checked'])) + { + print ''; + } + // Town + if (!empty($arrayfields['s.town']['checked'])) print ''; + // Zip + if (!empty($arrayfields['s.zip']['checked'])) print ''; + // State + if (!empty($arrayfields['state.nom']['checked'])) + { + print ''; + } + // Country + if (!empty($arrayfields['country.code_iso']['checked'])) + { + print ''; + } + // Company type + if (!empty($arrayfields['typent.code']['checked'])) + { + print ''; + } + // Payment mode + if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) + { + print ''; + } + if (!empty($arrayfields['f.total_ht']['checked'])) + { + // Amount without tax + print ''; + } + if (!empty($arrayfields['f.total_vat']['checked'])) + { + // Amount vat + print ''; + } + if (!empty($arrayfields['f.total_localtax1']['checked'])) + { + // Amount tax 1 + print ''; + } + if (!empty($arrayfields['f.total_localtax2']['checked'])) + { + // Amount tax 2 + print ''; + } + if (!empty($arrayfields['f.total_ttc']['checked'])) + { + // Amount inc tac + print ''; + } + if (!empty($arrayfields['u.login']['checked'])) + { + // Author + print ''; + } + if (!empty($arrayfields['dynamount_payed']['checked'])) + { + print ''; + } + if (!empty($arrayfields['rtp']['checked'])) + { + print ''; + } + if (!empty($arrayfields['f.multicurrency_code']['checked'])) + { + // Currency + print ''; + } + if (!empty($arrayfields['f.multicurrency_tx']['checked'])) + { + // Currency rate + print ''; + } + if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) + { + // Amount + print ''; + } + if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) + { + // Amount + print ''; + } + if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) + { + // Amount + print ''; + } + if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) + { + print ''; + } + if (!empty($arrayfields['multicurrency_rtp']['checked'])) + { + print ''; + } + // Extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; + + // Fields from hook + $parameters = array('arrayfields'=>$arrayfields); + $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook @@ -1033,254 +838,22 @@ - print ''; -} - -$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; -$selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields -$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); - -print '
'; -print '
'; + print ''; + print ''; + print ''; + print ''; + $listtype = array( + FactureFournisseur::TYPE_STANDARD=>$langs->trans("InvoiceStandard"), + FactureFournisseur::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"), + FactureFournisseur::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"), + FactureFournisseur::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"), + ); + /* + if (! empty($conf->global->INVOICE_USE_SITUATION)) + { + $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation"); + } + */ + //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order. + print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100'); + print ''; + print ''; + print ''; + if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; + print ''; + $formother->select_year($year ? $year : -1, 'year', 1, 20, 5); + print ''; + if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; + print ''; + $formother->select_year($year_lim ? $year_lim : -1, 'year_lim', 1, 20, 5); + print '
'.$langs->trans("Late"); + print '
'; + print ''; + print ''; + print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100'); + print ''; + print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT)); + print ''; + $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 10); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'."\n"; - -// Fields title search -// -------------------------------------------------------------------- -print ''; -// Action column -if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { - print ''; -} -// Ref -if (!empty($arrayfields['f.ref']['checked'])) { - print ''; -} -// Ref supplier -if (!empty($arrayfields['f.ref_supplier']['checked'])) { - print ''; -} -// Type -if (!empty($arrayfields['f.type']['checked'])) { - print ''; -} - // Invoice Subtype -if (!empty($arrayfields['f.subtype']['checked'])) { - print ''; -} -// Label -if (!empty($arrayfields['f.label']['checked'])) { - print ''; -} -// Date invoice -if (!empty($arrayfields['f.datef']['checked'])) { - print ''; -} -// Date due -if (!empty($arrayfields['f.date_lim_reglement']['checked'])) { - print ''; -} -// Project -if (!empty($arrayfields['p.ref']['checked'])) { - print ''; -} -// Thirpdarty -if (!empty($arrayfields['s.nom']['checked'])) { - print ''; -} -// Alias -if (!empty($arrayfields['s.name_alias']['checked'])) { - print ''; -} -// Town -if (!empty($arrayfields['s.town']['checked'])) { - print ''; -} -// Zip -if (!empty($arrayfields['s.zip']['checked'])) { - print ''; -} -// State -if (!empty($arrayfields['state.nom']['checked'])) { - print ''; -} -// Country -if (!empty($arrayfields['country.code_iso']['checked'])) { - print ''; -} -// Company type -if (!empty($arrayfields['typent.code']['checked'])) { - print ''; -} -// Condition of payment -if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) { - print ''; -} -// Payment mode -if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) { - print ''; -} -if (!empty($arrayfields['f.total_ht']['checked'])) { - // Amount without tax - print ''; -} -if (!empty($arrayfields['f.total_vat']['checked'])) { - // Amount vat - print ''; -} -if (!empty($arrayfields['f.total_localtax1']['checked'])) { - // Amount tax 1 - print ''; -} -if (!empty($arrayfields['f.total_localtax2']['checked'])) { - // Amount tax 2 - print ''; -} -if (!empty($arrayfields['f.total_ttc']['checked'])) { - // Amount inc tac - print ''; -} -if (!empty($arrayfields['f.nb_docs']['checked'])) { - // Nb of attached documents - print ''; -} -if (!empty($arrayfields['u.login']['checked'])) { - // Author - print ''; -} -if (!empty($arrayfields['dynamount_payed']['checked'])) { - print ''; -} -if (!empty($arrayfields['rtp']['checked'])) { - print ''; -} -if (!empty($arrayfields['f.multicurrency_code']['checked'])) { - // Currency - print ''; -} -if (!empty($arrayfields['f.multicurrency_tx']['checked'])) { - // Currency rate - print ''; -} -if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) { - // Amount - print ''; -} -if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) { - // Amount - print ''; -} -if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) { - // Amount - print ''; -} -if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) { - print ''; -} -if (!empty($arrayfields['multicurrency_rtp']['checked'])) { - print ''; -} -// Extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; - -// Fields from hook -$parameters = array('arrayfields'=>$arrayfields); -$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook -print $hookmanager->resPrint; -// Date creation -if (!empty($arrayfields['f.datec']['checked'])) { - print ''; -} -// Date modification -if (!empty($arrayfields['f.tms']['checked'])) { - print ''; -} -// Status -if (!empty($arrayfields['f.fk_statut']['checked'])) { - print ''; -} -// Action column -if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { - print ''; + } + // Date modification + if (!empty($arrayfields['f.tms']['checked'])) + { + print ''; + } + // Status + if (!empty($arrayfields['f.fk_statut']['checked'])) + { + print ''; + } + // Action column + print '\n"; - -$totalarray = array(); -$totalarray['nbfield'] = 0; - -// Fields title label -// -------------------------------------------------------------------- -print ''; -// Action column -if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { - print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.ref']['checked'])) { - print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref,f.rowid', '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.ref_supplier']['checked'])) { - print_liste_field_titre($arrayfields['f.ref_supplier']['label'], $_SERVER["PHP_SELF"], 'f.ref_supplier', '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.type']['checked'])) { - print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.subtype']['checked'])) { - print_liste_field_titre($arrayfields['f.subtype']['label'], $_SERVER["PHP_SELF"], 'f.subtype', '', $param, '', $sortfield, $sortorder); -} -if (!empty($arrayfields['f.label']['checked'])) { - print_liste_field_titre($arrayfields['f.label']['label'], $_SERVER['PHP_SELF'], "f.libelle,f.rowid", '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.datef']['checked'])) { - print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef,f.rowid', '', $param, '', $sortfield, $sortorder, 'center '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.date_lim_reglement']['checked'])) { - print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['p.ref']['checked'])) { - print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['s.nom']['checked'])) { - print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['s.name_alias']['checked'])) { - print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['s.town']['checked'])) { - print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['s.zip']['checked'])) { - print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder, 'center '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['state.nom']['checked'])) { - print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.name_alias", "", $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['state.name_alias']['checked'])) { - print_liste_field_titre($arrayfields['state.name_alias']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['country.code_iso']['checked'])) { - print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['typent.code']['checked'])) { - print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) { - print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) { - print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.total_ht']['checked'])) { - print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.total_vat']['checked'])) { - print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.total_localtax1']['checked'])) { - print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.total_localtax2']['checked'])) { - print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.total_ttc']['checked'])) { - print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.nb_docs']['checked'])) { - print_liste_field_titre($arrayfields['f.nb_docs']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['u.login']['checked'])) { - print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['dynamount_payed']['checked'])) { - print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['rtp']['checked'])) { - print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.multicurrency_code']['checked'])) { - print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.multicurrency_tx']['checked'])) { - print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) { - print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, '"', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) { - print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) { - print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) { - print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['multicurrency_rtp']['checked'])) { - print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; -} -// Extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; -// Hook fields -$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray); -$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook -print $hookmanager->resPrint; -if (!empty($arrayfields['f.datec']['checked'])) { - print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.tms']['checked'])) { - print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); - $totalarray['nbfield']++; -} -if (!empty($arrayfields['f.fk_statut']['checked'])) { - print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'center '); - $totalarray['nbfield']++; -} -// Action column -if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { - print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; - $totalarray['nbfield']++; -} -print ''."\n"; - -$facturestatic = new FactureFournisseur($db); -$supplierstatic = new Fournisseur($db); -$projectstatic = new Project($db); -$userstatic = new User($db); -$discount = new DiscountAbsolute($db); - -// Loop on record -// -------------------------------------------------------------------- -$i = 0; -$savnbfield = $totalarray['nbfield']; -$totalarray = array(); -$totalarray['nbfield'] = 0; -$totalarray['val'] = array(); -$totalarray['val']['f.total_ht']=0; -$totalarray['val']['f.total_vat']=0; -$totalarray['val']['f.total_localtax1']=0; -$totalarray['val']['f.total_localtax1']=0; -$totalarray['val']['f.total_ttc']=0; -$totalarray['val']['totalam']=0; -$totalarray['val']['rtp']=0; -$imaxinloop = ($limit ? min($num, $limit) : $num); -while ($i < $imaxinloop) { - $obj = $db->fetch_object($resql); - if (empty($obj)) { - break; // Should not happen - } - - $datelimit = $db->jdate($obj->datelimite); - - $userstatic->id = $obj->fk_user_author; - $userstatic->login = $obj->login; - $userstatic->lastname = $obj->lastname; - $userstatic->firstname = $obj->firstname; - $userstatic->email = $obj->user_email; - $userstatic->statut = $obj->user_statut; - $userstatic->status = $obj->user_statut; - $userstatic->entity = $obj->entity; - $userstatic->photo = $obj->photo; - $userstatic->office_phone = $obj->office_phone; - $userstatic->office_fax = $obj->office_fax; - $userstatic->user_mobile = $obj->user_mobile; - $userstatic->job = $obj->job; - $userstatic->gender = $obj->gender; - $facturestatic->id = $obj->facid; - $facturestatic->ref = $obj->ref; - $facturestatic->type = $obj->type; - $facturestatic->subtype = $obj->subtype; - $facturestatic->total_ht = $obj->total_ht; - $facturestatic->total_tva = $obj->total_vat; - $facturestatic->total_ttc = $obj->total_ttc; - $facturestatic->close_code = $obj->close_code; - $facturestatic->ref_supplier = $obj->ref_supplier; - $facturestatic->date_echeance = $db->jdate($obj->datelimite); - $facturestatic->statut = $obj->fk_statut; - $facturestatic->status = $obj->fk_statut; - $facturestatic->note_public = $obj->note_public; - $facturestatic->note_private = $obj->note_private; - $facturestatic->multicurrency_code = $obj->multicurrency_code; - $facturestatic->multicurrency_tx = $obj->multicurrency_tx; - $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht; - $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat; - $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc; - $thirdparty->id = $obj->socid; - $thirdparty->name = $obj->name; - $thirdparty->name_alias = $obj->alias; - $thirdparty->client = $obj->client; - $thirdparty->fournisseur = $obj->fournisseur; - $thirdparty->code_client = $obj->code_client; - $thirdparty->code_compta_client = $obj->code_compta_client; - $thirdparty->code_fournisseur = $obj->code_fournisseur; - $thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur; - $thirdparty->email = $obj->email; - $thirdparty->country_code = $obj->country_code; - - $paiement = $facturestatic->getSommePaiement(); - $totalcreditnotes = $facturestatic->getSumCreditNotesUsed(); - $totaldeposits = $facturestatic->getSumDepositsUsed(); - $totalpay = $paiement + $totalcreditnotes + $totaldeposits; - $remaintopay = $obj->total_ttc - $totalpay; - - $multicurrency_paiement = $facturestatic->getSommePaiement(1); - $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1); - $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1); - - $totalpay = $paiement + $totalcreditnotes + $totaldeposits; - $remaintopay = price2num($facturestatic->total_ttc - $totalpay); - - $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits; - $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay); - - if ($facturestatic->status == FactureFournisseur::STATUS_CLOSED && $facturestatic->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment - $remaintopay = 0; - $multicurrency_remaintopay = 0; - } - if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consumed - $remaincreditnote = $discount->getAvailableDiscounts($thirdparty, '', 'rc.fk_facture_source='.$facturestatic->id); - $remaintopay = -$remaincreditnote; - $totalpay = price2num($facturestatic->total_ttc - $remaintopay); - $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($thirdparty, '', 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1); - $multicurrency_remaintopay = -$multicurrency_remaincreditnote; - $multicurrency_totalpay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay); - } - - $facturestatic->alreadypaid = ($paiement ? $paiement : 0); - - $facturestatic->paye = $obj->paye; - $facturestatic->socid = $thirdparty->getNomUrl(1, 'supplier', 3); - - $facturestatic->date = $db->jdate($obj->datef); - - $object = $facturestatic; - - //If invoice has been converted and the conversion has been used, we dont have remain to pay on invoice - if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) { - if ($facturestatic->isCreditNoteUsed()) { - $remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed(); + + print "\n"; + + print ''; + if (!empty($arrayfields['f.ref']['checked'])) print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref,f.rowid', '', $param, '', $sortfield, $sortorder); + if (!empty($arrayfields['f.ref_supplier']['checked'])) print_liste_field_titre($arrayfields['f.ref_supplier']['label'], $_SERVER["PHP_SELF"], 'f.ref_supplier', '', $param, '', $sortfield, $sortorder); + if (!empty($arrayfields['f.type']['checked'])) print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder); + if (!empty($arrayfields['f.label']['checked'])) print_liste_field_titre($arrayfields['f.label']['label'], $_SERVER['PHP_SELF'], "f.libelle,f.rowid", '', $param, '', $sortfield, $sortorder); + if (!empty($arrayfields['f.datef']['checked'])) print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef,f.rowid', '', $param, '', $sortfield, $sortorder, 'center '); + if (!empty($arrayfields['f.date_lim_reglement']['checked'])) print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center '); + if (!empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder); + if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder); + if (!empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder); + if (!empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder, 'center '); + if (!empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder); + if (!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center '); + if (!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center '); + if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder); + if (!empty($arrayfields['f.total_ht']['checked'])) print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right '); + if (!empty($arrayfields['f.total_vat']['checked'])) print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.tva', '', $param, '', $sortfield, $sortorder, 'right '); + if (!empty($arrayfields['f.total_localtax1']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right '); + if (!empty($arrayfields['f.total_localtax2']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right '); + if (!empty($arrayfields['f.total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right '); + if (!empty($arrayfields['u.login']['checked'])) print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder); + if (!empty($arrayfields['dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right '); + if (!empty($arrayfields['rtp']['checked'])) print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right '); + if (!empty($arrayfields['f.multicurrency_code']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder); + if (!empty($arrayfields['f.multicurrency_tx']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder); + if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder); + if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder); + if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder); + if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + if (!empty($arrayfields['multicurrency_rtp']['checked'])) print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + // Extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; + // Hook fields + $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); + $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (!empty($arrayfields['f.datec']['checked'])) print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + if (!empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + if (!empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'right '); + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); + print "\n"; + + $facturestatic = new FactureFournisseur($db); + $supplierstatic = new Fournisseur($db); + $projectstatic = new Project($db); + $userstatic = new User($db); + + if ($num > 0) + { + $i = 0; + $totalarray = array(); + while ($i < min($num, $limit)) + { + $obj = $db->fetch_object($resql); + + $datelimit = $db->jdate($obj->datelimite); + $facturestatic->id = $obj->facid; + $facturestatic->ref = $obj->ref; + $facturestatic->type = $obj->type; + $facturestatic->ref_supplier = $obj->ref_supplier; + $facturestatic->date_echeance = $db->jdate($obj->datelimite); + $facturestatic->statut = $obj->fk_statut; + $facturestatic->note_public = $obj->note_public; + $facturestatic->note_private = $obj->note_private; + $facturestatic->multicurrency_code = $obj->multicurrency_code; + $facturestatic->multicurrency_tx = $obj->multicurrency_tx; + $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht; + $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat; + $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc; + + $thirdparty->id = $obj->socid; + $thirdparty->name = $obj->name; + $thirdparty->client = $obj->client; + $thirdparty->fournisseur = $obj->fournisseur; + $thirdparty->code_client = $obj->code_client; + $thirdparty->code_compta_client = $obj->code_compta_client; + $thirdparty->code_fournisseur = $obj->code_fournisseur; + $thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur; + $thirdparty->email = $obj->email; + $thirdparty->country_code = $obj->country_code; + + $paiement = $facturestatic->getSommePaiement(); + $totalcreditnotes = $facturestatic->getSumCreditNotesUsed(); + $totaldeposits = $facturestatic->getSumDepositsUsed(); + $totalpay = $paiement + $totalcreditnotes + $totaldeposits; + $remaintopay = $obj->total_ttc - $totalpay; + $multicurrency_paiement = $facturestatic->getSommePaiement(1); + $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1); + $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1); + $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits; + $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay); + + $facturestatic->alreadypaid = ($paiement ? $paiement : 0); + $facturestatic->paye = $obj->paye; + $facturestatic->statut = $obj->fk_statut; + $facturestatic->type = $obj->type; + + + //If invoice has been converted and the conversion has been used, we dont have remain to pay on invoice + if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) { + if ($facturestatic->isCreditNoteUsed()) { + $remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed(); + } + } + + print ''; + if (!empty($arrayfields['f.ref']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + } + + // Supplier ref + if (!empty($arrayfields['f.ref_supplier']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + + // Type + if (!empty($arrayfields['f.type']['checked'])) + { + print '"; + if (!$i) $totalarray['nbfield']++; + } + + // Label + if (!empty($arrayfields['f.label']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + + // Date + if (!empty($arrayfields['f.datef']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + + // Date limit + if (!empty($arrayfields['f.date_lim_reglement']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + + // Project + if (!empty($arrayfields['p.ref']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + + // Third party + if (!empty($arrayfields['s.nom']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + // Town + if (!empty($arrayfields['s.town']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + // Zip + if (!empty($arrayfields['s.zip']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + // State + if (!empty($arrayfields['state.nom']['checked'])) + { + print "\n"; + if (!$i) $totalarray['nbfield']++; + } + // Country + if (!empty($arrayfields['country.code_iso']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + // Type ent + if (!empty($arrayfields['typent.code']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + + // Payment mode + if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + + // Amount HT + if (!empty($arrayfields['f.total_ht']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht'; + $totalarray['val']['f.total_ht'] += $obj->total_ht; + } + // Amount VAT + if (!empty($arrayfields['f.total_vat']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat'; + $totalarray['val']['f.total_vat'] += $obj->total_vat; + } + // Amount LocalTax1 + if (!empty($arrayfields['f.total_localtax1']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1'; + $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1; + } + // Amount LocalTax2 + if (!empty($arrayfields['f.total_localtax2']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2'; + $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2; + } + // Amount TTC + if (!empty($arrayfields['f.total_ttc']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc'; + $totalarray['val']['f.total_ttc'] += $obj->total_ttc; + } + + // Author + if (!empty($arrayfields['u.login']['checked'])) + { + $userstatic->id = $obj->fk_user_author; + $userstatic->login = $obj->login; + print '\n"; + if (!$i) $totalarray['nbfield']++; + } + + if (!empty($arrayfields['dynamount_payed']['checked'])) + { + print ''; // TODO Use a denormalized field + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalam'; + $totalarray['val']['totalam'] += $totalpay; + } + + if (!empty($arrayfields['rtp']['checked'])) + { + print ''; // TODO Use a denormalized field + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'rtp'; + $totalarray['val']['rtp'] += $remaintopay; + } + + // Currency + if (!empty($arrayfields['f.multicurrency_code']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + } + + // Currency rate + if (!empty($arrayfields['f.multicurrency_tx']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + } + // Amount HT + if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + } + // Amount VAT + if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + } + // Amount TTC + if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + } + if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) + { + print ''; // TODO Use a denormalized field + if (!$i) $totalarray['nbfield']++; + } + + // Pending amount + if (!empty($arrayfields['multicurrency_rtp']['checked'])) + { + print ''; // TODO Use a denormalized field + if (!$i) $totalarray['nbfield']++; + } + + + // Extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; + // Fields from hook + $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray); + $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + // Date creation + if (!empty($arrayfields['f.datec']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + // Date modification + if (!empty($arrayfields['f.tms']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + // Status + if (!empty($arrayfields['f.fk_statut']['checked'])) + { + print '"; + if (!$i) $totalarray['nbfield']++; + } + + // Action column + print ''; + if (!$i) $totalarray['nbfield']++; + + print "\n"; + + $i++; @@ -1582,465 +1276,16 @@ - } - - if ($mode == 'kanban') { - if ($i == 0) { - print ''; - } - } else { - // Show line of result - $j = 0; - print ''; - - // Action column - if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - if (!empty($arrayfields['f.ref']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Supplier ref - if (!empty($arrayfields['f.ref_supplier']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Type - if (!empty($arrayfields['f.type']['checked'])) { - print '"; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Invoice Subtype - if (!empty($arrayfields['f.subtype']['checked'])) { - $labeltoshow = ''; - if ($facturestatic->subtype > 0) { - $labeltoshow = $facturestatic->getSubtypeLabel('facture_fourn'); - } - print '"; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Label - if (!empty($arrayfields['f.label']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Date - if (!empty($arrayfields['f.datef']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Date limit - if (!empty($arrayfields['f.date_lim_reglement']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Project - if (!empty($arrayfields['p.ref']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Third party - if (!empty($arrayfields['s.nom']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Alias - if (!empty($arrayfields['s.name_alias']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Town - if (!empty($arrayfields['s.town']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Zip - if (!empty($arrayfields['s.zip']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // State - if (!empty($arrayfields['state.nom']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Country - if (!empty($arrayfields['country.code_iso']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Type ent - if (!empty($arrayfields['typent.code']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Payment condition - if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) { - $s = $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 1, '', -1, -1, 1); - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Payment mode - if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) { - $s = $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1, 0, '', 1); - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Amount HT - if (!empty($arrayfields['f.total_ht']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht'; - } - $totalarray['val']['f.total_ht'] += $obj->total_ht; - } - // Amount VAT - if (!empty($arrayfields['f.total_vat']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat'; - } - $totalarray['val']['f.total_vat'] += $obj->total_vat; - } - // Amount LocalTax1 - if (!empty($arrayfields['f.total_localtax1']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1'; - } - $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1; - } - // Amount LocalTax2 - if (!empty($arrayfields['f.total_localtax2']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2'; - } - $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2; - } - // Amount TTC - if (!empty($arrayfields['f.total_ttc']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc'; - } - $totalarray['val']['f.total_ttc'] += $obj->total_ttc; - } - - // Number of attached documents - if (!empty($arrayfields['f.nb_docs']['checked'])) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; - $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice_supplier').$facturestatic->ref; - $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); - $nbLinks = Link::count($db, $facturestatic->element, $facturestatic->id); - $nbTotal = $nbFiles + $nbLinks; - echo ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Author - if (!empty($arrayfields['u.login']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - } - } - - if (!empty($arrayfields['dynamount_payed']['checked'])) { - print ''; // TODO Use a denormalized field - if (!$i) { - $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'totalam'; - } - if (empty($totalarray['val']['totalam'])) { - $totalarray['val']['totalam'] = 0; // avoid PHP Warning: Undefined array key "totalam" on line 1891 - } - $totalarray['val']['totalam'] += $totalpay; - } - - if (!empty($arrayfields['rtp']['checked'])) { - print ''; // TODO Use a denormalized field - if (!$i) { - $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'rtp'; - } - $totalarray['val']['rtp'] += $remaintopay; - } - - // Currency - if (!empty($arrayfields['f.multicurrency_code']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Currency rate - if (!empty($arrayfields['f.multicurrency_tx']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Amount HT - if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Amount VAT - if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Amount TTC - if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - } - } - if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) { - print ''; // TODO Use a denormalized field - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Pending amount - if (!empty($arrayfields['multicurrency_rtp']['checked'])) { - print ''; // TODO Use a denormalized field - if (!$i) { - $totalarray['nbfield']++; - } - } - - - // Extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; - // Fields from hook - $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray); - $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - - // Date creation - if (!empty($arrayfields['f.datec']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Date modification - if (!empty($arrayfields['f.tms']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Status - if (!empty($arrayfields['f.fk_statut']['checked'])) { - print '"; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Action column - if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - print ''."\n"; - } - - $i++; -} - -// Show total line -include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; - -// If no record found -if ($num == 0) { - $colspan = 1; - foreach ($arrayfields as $key => $val) { - if (!empty($val['checked'])) { - $colspan++; - } - } - print ''; -} - -$db->free($resql); - -$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql); -$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook -print $hookmanager->resPrint; - -print '
'; - $searchpicto = $form->showFilterButtons('left'); - print $searchpicto; - print ''; - print ''; - print ''; - print ''; - print ''; - $listtype = array( - FactureFournisseur::TYPE_STANDARD=>$langs->trans("InvoiceStandard"), - FactureFournisseur::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"), - FactureFournisseur::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"), - FactureFournisseur::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"), - ); - /* - if (!empty($conf->global->INVOICE_USE_SITUATION)) - { - $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation"); - } - */ - //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order. - print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100'); - print ''; - print $form->selectarray('search_subtype', $subtypearray, $search_subtype, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100'); - print ''; - print ''; - print ''; - print '
'; - print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); - print '
'; - print '
'; - print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); - print '
'; - print '
'; - print '
'; - /* - print $langs->trans('From').' '; - print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1); - print '
'; - print '
'; - print $langs->trans('to').' ';*/ - print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before")); - //print '
'; - print '
'; - print '
'; - print '
0 ? " disabled" : "").'>'; - print ''; - print ''; - print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100'); - print ''; - print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1); - print ''; - print $form->getSelectConditionsPaiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100'); - print ''; - print $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 20, 1, 'maxwidth100', 1); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $liststatus = array('0'=>$langs->trans("Draft"), '1'=>$langs->trans("Unpaid"), '2'=>$langs->trans("Paid")); - print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'center search_status width100 onrightofpage', 1); - print ''; + // Date creation + if (!empty($arrayfields['f.datec']['checked'])) + { + print ''; + print ''; + print ''; + $liststatus = array('0'=>$langs->trans("Draft"), '1'=>$langs->trans("Unpaid"), '2'=>$langs->trans("Paid")); + print $form->selectarray('search_status', $liststatus, $search_status, 1); + print ''; @@ -1290,291 +863,412 @@ -} - -print "
'; + + print ''; + // Picto + Ref + print '
'; + print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1); + + $filename = dol_sanitizeFileName($obj->ref); + $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref); + $subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref); + print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir); + print '
'; + + print "
'; + print $obj->ref_supplier; + print ''; + print $facturestatic->getLibType(); + print "'; + print $obj->label; + print ''; + print dol_print_date($db->jdate($obj->datef), 'day'); + print ''.dol_print_date($datelimit, 'day'); + if ($facturestatic->hasDelay()) + { + print img_warning($langs->trans('Late')); + } + print ''; + if ($obj->project_id > 0) + { + $projectstatic->id = $obj->project_id; + $projectstatic->ref = $obj->project_ref; + $projectstatic->title = $obj->project_label; + print $projectstatic->getNomUrl(1); + } + print ''; + print $thirdparty->getNomUrl(1, 'supplier'); + print ''; + print $obj->town; + print ''; + print $obj->zip; + print '".$obj->state_name."'; + $tmparray = getCountry($obj->fk_pays, 'all'); + print $tmparray['label']; + print ''; + if (count($typenArray) == 0) $typenArray = $formcompany->typent_array(1); + print $typenArray[$obj->typent_code]; + print ''; + $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1); + print ''.price($obj->total_ht)."'.price($obj->total_vat)."'.price($obj->total_localtax1)."'.price($obj->total_localtax2)."'.price($obj->total_ttc)."'; + if ($userstatic->id) print $userstatic->getLoginUrl(1); + else print ' '; + print "'.(!empty($totalpay) ?price($totalpay, 0, $langs) : ' ').''.(!empty($remaintopay) ?price($remaintopay, 0, $langs) : ' ').''.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."'; + $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code); + print "'.price($obj->multicurrency_total_ht)."'.price($obj->multicurrency_total_vat)."'.price($obj->multicurrency_total_ttc)."'.(!empty($multicurrency_totalpay) ?price($multicurrency_totalpay, 0, $langs) : ' ').''; + print (!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : ' '); + print ''; + print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser'); + print ''; + print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser'); + print ''; + print $facturestatic->LibStatut($obj->paye, $obj->fk_statut, 5, $paiement, $obj->type); + print "'; + if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + { + $selected = 0; + if (in_array($obj->facid, $arrayofselected)) $selected = 1; + print ''; + } + print '
'; - print '
'; - } - // Output Kanban - if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - $selected = 0; - if (in_array($object->id, $arrayofselected)) { - $selected = 1; - } - } - - $arraydata = array('alreadypaid' => $paiement, 'thirdparty' => $thirdparty->getNomUrl(1, '', 12), 'selected' => in_array($object->id, $arrayofselected)); - print $facturestatic->getKanbanView('', $arraydata); - if ($i == ($imaxinloop - 1)) { - print '
'; - print '
'; - if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - $selected = 0; - if (in_array($obj->facid, $arrayofselected)) { - $selected = 1; - } - print ''; - } - print ''; - - print ''; - // Picto + Ref - print '
'; - print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1); - - $filename = dol_sanitizeFileName($obj->ref); - $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref); - $subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref); - print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir); - print '
'; - - print "
'; - print $obj->ref_supplier; - print ''; - print $facturestatic->getLibType(); - print "'; - print $labeltoshow; - print "'; - print dol_escape_htmltag($obj->label); - print ''; - print dol_print_date($db->jdate($obj->datef), 'day'); - print ''.dol_print_date($datelimit, 'day'); - if ($facturestatic->hasDelay()) { - print img_warning($langs->trans('Alert').' - '.$langs->trans('Late')); - } - print ''; - if ($obj->project_id > 0) { - $projectstatic->id = $obj->project_id; - $projectstatic->ref = $obj->project_ref; - $projectstatic->title = $obj->project_label; - print $projectstatic->getNomUrl(1); - } - print ''; - print $thirdparty->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1); - print ''; - print dol_escape_htmltag($thirdparty->name_alias); - print ''; - print dol_escape_htmltag($obj->town); - print ''; - print dol_escape_htmltag($obj->zip); - print ''; - print dol_escape_htmltag($obj->state_name); - print "'; - $tmparray = getCountry($obj->fk_pays, 'all'); - print $tmparray['label']; - print ''; - if (empty($typenArray)) { - $typenArray = $formcompany->typent_array(1); - } - print $typenArray[$obj->typent_code]; - print ''; - print dol_escape_htmltag($s); - print ''; - print dol_escape_htmltag($s); - print ''.price($obj->total_ht)."'.price($obj->total_vat)."'.price($obj->total_localtax1)."'.price($obj->total_localtax2)."'.price($obj->total_ttc)."'.(empty($nbTotal) ? '' : $nbTotal).''; - if ($userstatic->id) { - print $userstatic->getNomUrl(-1); - } else { - print ' '; - } - print "'.(!empty($totalpay) ? price($totalpay, 0, $langs) : '').''.(!empty($remaintopay) ? price($remaintopay, 0, $langs) : ' ').''.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."'; - $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code); - print "'.price($obj->multicurrency_total_ht)."'.price($obj->multicurrency_total_vat)."'.price($obj->multicurrency_total_ttc)."'.(!empty($multicurrency_totalpay) ? price($multicurrency_totalpay, 0, $langs) : '').''; - print(!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : ''); - print ''; - print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser'); - print ''; - print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser'); - print ''; - print $facturestatic->getLibStatut(5, $paiement); - print "'; - if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - $selected = 0; - if (in_array($obj->facid, $arrayofselected)) { - $selected = 1; - } - print ''; - } - print '
'.$langs->trans("NoRecordFound").'
'."\n"; -print '
'."\n"; - -print ''."\n"; - -if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) { + + // Show total line + include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; + } + + $db->free($resql); + + $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql); + $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + print "\n"; + print '
'; + + print "\n"; + @@ -2048,17 +1293,16 @@ - if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { - $hidegeneratedfilelistifempty = 0; - } - - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; - $formfile = new FormFile($db); - - // Show list of available documents - $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; - $urlsource .= str_replace('&', '&', $param); - - $filedir = $diroutputmassaction; - $genallowed = $permissiontoread; - $delallowed = $permissiontoadd; - $title = ''; - - print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; + + // Show list of available documents + $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; + $urlsource .= str_replace('&', '&', $param); + + $filedir = $diroutputmassaction; + $genallowed = $user->rights->facture->lire; + $delallowed = $user->rights->facture->creer; + $title = ''; + + print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); +} +else +{ + dol_print_error($db); --- /tmp/dsg/dolibarr/htdocs/fourn/facture/github_19.0.3_note.php +++ /tmp/dsg/dolibarr/htdocs/fourn/facture/client_note.php @@ -6,2 +6 @@ - * Copyright (C) 2017 Ferran Marcet - * Copyright (C) 2021 Frédéric France + * Copyright (C) 2017 Ferran Marcet @@ -29 +27,0 @@ -// Load Dolibarr environment @@ -34 +32 @@ -if (isModEnabled('project')) { +if (!empty($conf->projet->enabled)) { @@ -42 +40 @@ -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); @@ -45,6 +43 @@ -if ($user->socid) { - $socid = $user->socid; -} -// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context -$hookmanager->initHooks(array('invoicesuppliernote')); - +if ($user->socid) $socid = $user->socid; @@ -56,3 +49 @@ -$usercancreate = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); -$permissiontoadd = $usercancreate; -$permissionnote = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); // Used by the include of actions_setnotes.inc.php +$permissionnote = $user->rights->fournisseur->facture->creer; // Used by the include of actions_setnotes.inc.php @@ -65,7 +56 @@ -$reshook = $hookmanager->executeHooks('doActions', array(), $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)) { - include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once -} +include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once @@ -74,2 +59,3 @@ -if ($action == 'setlabel' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { - $object->label = GETPOST('label'); +if ($action == 'setlabel' && $user->rights->fournisseur->facture->creer) +{ + $object->label = $_POST['label']; @@ -77,3 +63 @@ - if ($result < 0) { - dol_print_error($db); - } + if ($result < 0) dol_print_error($db); @@ -89 +73 @@ -$title = $object->ref." - ".$langs->trans('Notes'); +$title = $langs->trans('SupplierInvoice')." - ".$langs->trans('Notes'); @@ -93 +77,2 @@ -if ($object->id > 0) { +if ($object->id > 0) +{ @@ -100 +85 @@ - print dol_get_fiche_head($head, 'note', $titre, -1, 'supplier_invoice'); + dol_fiche_head($head, 'note', $titre, -1, 'bill'); @@ -104,19 +89,19 @@ - $linkback = ''.$langs->trans("BackToList").''; - - $morehtmlref = '
'; - // Ref supplier - $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1); - // Thirdparty - $morehtmlref .= '
'.$object->thirdparty->getNomUrl(1); - if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) { - $morehtmlref .= ' '; - } - // Project - if (isModEnabled('project')) { - $langs->load("projects"); - $morehtmlref .= '
'; - if (0) { - $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); - if ($action != 'classify') { - $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; + $linkback = ''.$langs->trans("BackToList").''; + + $morehtmlref = '
'; + // Ref supplier + $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); + if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' ('.$langs->trans("OtherBills").')'; + // Project + if (!empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref .= '
'.$langs->trans('Project').' '; + if ($user->rights->fournisseur->commande->creer) + { + if ($action != 'classify') { + // $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + $morehtmlref .= ' : '; @@ -124,20 +109,31 @@ - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); - } else { - if (!empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref .= $proj->getNomUrl(1); - if ($proj->title) { - $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; - } - } - } - } - $morehtmlref .= '
'; - - $object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status - - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - print '
'; - print '
'; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref .= ''; + $morehtmlref .= '
'; + } else { + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (!empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref .= ''; + $morehtmlref .= $proj->ref; + $morehtmlref .= ''; + } else { + $morehtmlref .= ''; + } + } + } + $morehtmlref .= '
'; + + $object->totalpaye = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + + print '
'; + print '
'; @@ -147 +143 @@ - // Type + // Type @@ -149 +144,0 @@ - print ''; @@ -151,2 +146,2 @@ - print ''; - if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) { + if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) + { @@ -157 +152,2 @@ - if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) { + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) + { @@ -164,3 +160,8 @@ - if (count($facidavoir) > 0) { - $invoicecredits = array(); - foreach ($facidavoir as $facid) { + if (count($facidavoir) > 0) + { + print ' ('.$langs->transnoentities("InvoiceHasAvoir"); + $i = 0; + foreach ($facidavoir as $fid) + { + if ($i == 0) print ' '; + else print ','; @@ -168,2 +169,2 @@ - $facavoir->fetch($facid); - $invoicecredits[] = $facavoir->getNomUrl(1); + $facavoir->fetch($fid); + print $facavoir->getNomUrl(1); @@ -171,4 +172,4 @@ - print ' ('.$langs->transnoentities("InvoiceHasAvoir") . implode(',', $invoicecredits) . ')'; - } - /* - if ($facidnext > 0) { + print ')'; + } + if ($facidnext > 0) + { @@ -179 +179,0 @@ - */ @@ -193,2 +193,3 @@ - if ($mysoc->localtax1_assuj == "1") { //Localtax1 - print ''.$langs->transcountry("AmountLT1", $mysoc->country_code).''; + if ($societe->localtax1_assuj == "1") //Localtax1 + { + print ''.$langs->transcountry("AmountLT1", $societe->country_code).''; @@ -198,2 +199,3 @@ - if ($mysoc->localtax2_assuj == "1") { //Localtax2 - print ''.$langs->transcountry("AmountLT2", $mysoc->country_code).''; + if ($societe->localtax2_assuj == "1") //Localtax2 + { + print ''.$langs->transcountry("AmountLT2", $societe->country_code).''; @@ -209 +211 @@ - print '
'; + print '
'; @@ -213 +215 @@ - print dol_get_fiche_end(); + dol_fiche_end(); --- /tmp/dsg/dolibarr/htdocs/fourn/facture/github_19.0.3_paiement.php +++ /tmp/dsg/dolibarr/htdocs/fourn/facture/client_paiement.php @@ -12,4 +12 @@ - * Copyright (C) 2018-2020 Frédéric France - * Copyright (C) 2021 Charlene Benke - * Copyright (C) 2022 Udo Tamm - * Copyright (C) 2023 Sylvain Legrand + * Copyright (C) 2018 Frédéric France @@ -37 +33,0 @@ -// Load Dolibarr environment @@ -44 +39,0 @@ -require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -49,2 +44,2 @@ -$action = GETPOST('action', 'alpha'); -$confirm = GETPOST('confirm', 'alpha'); +$action = GETPOST('action', 'alpha'); +$confirm = GETPOST('confirm', 'alpha'); @@ -52,6 +47,3 @@ -$cancel = GETPOST('cancel', 'alpha'); -$backtopage = GETPOST('backtopage', 'alpha'); -$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); - -$facid = GETPOST('facid', 'int'); -$socid = GETPOST('socid', 'int'); + +$facid = GETPOST('facid', 'int'); +$socid = GETPOST('socid', 'int'); @@ -60 +52 @@ -$month = GETPOST('month', 'int'); +$month = GETPOST('month', 'int'); @@ -63,5 +55,5 @@ -$search_ref = GETPOST('search_ref', 'alpha'); -$search_account = GETPOST('search_account', 'int'); -$search_paymenttype = GETPOST('search_paymenttype'); -$search_amount = GETPOST('search_amount', 'alpha'); // alpha because we must be able to search on "< x" -$search_company = GETPOST('search_company', 'alpha'); +$search_ref = GETPOST("search_ref", "alpha"); +$search_account = GETPOST("search_account", "int"); +$search_paymenttype = GETPOST("search_paymenttype"); +$search_amount = GETPOST("search_amount", 'alpha'); // alpha because we must be able to search on "< x" +$search_company = GETPOST("search_company", 'alpha'); @@ -70,3 +62,3 @@ -$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); @@ -74,3 +66 @@ -if (empty($page) || $page == -1) { - $page = 0; -} // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 @@ -80,6 +70,2 @@ -if (!$sortorder) { - $sortorder = "DESC"; -} -if (!$sortfield) { - $sortfield = "p.rowid"; -} +if (!$sortorder) $sortorder = "DESC"; +if (!$sortfield) $sortfield = "p.rowid"; @@ -95,2 +81,3 @@ -if ($user->socid > 0) { - $socid = $user->socid; +if ($user->socid > 0) +{ + $socid = $user->socid; @@ -118,23 +105,12 @@ -if ($cancel) { - if (!empty($backtopageforcancel)) { - header("Location: ".$backtopageforcancel); - exit; - } elseif (!empty($backtopage)) { - header("Location: ".$backtopage); - exit; - } - header("Location: ".DOL_URL_ROOT.'/fourn/facture/list.php'); - exit; -} - -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers - $search_ref = ""; - $search_account = ""; - $search_amount = ""; - $search_paymenttype = ""; - $search_payment_num = ""; - $search_company = ""; - $day = ''; - $year = ''; - $month = ''; - $search_array_options = array(); +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers +{ + $search_ref = ""; + $search_account = ""; + $search_amount = ""; + $search_paymenttype = ""; + $search_payment_num = ""; + $search_company = ""; + $day = ''; + $year = ''; + $month = ''; + $search_array_options = array(); @@ -145,49 +121,53 @@ -if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -} - -if (empty($reshook)) { - if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes')) { - $error = 0; - - $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - $paiement_id = 0; - $totalpayment = 0; - $atleastonepaymentnotnull = 0; - $multicurrency_totalpayment = 0; - - // Generate payment array and check if there is payment higher than invoice and payment date before invoice date - $tmpinvoice = new FactureFournisseur($db); - foreach ($_POST as $key => $value) { - if (substr($key, 0, 7) == 'amount_') { - $cursorfacid = substr($key, 7); - $amounts[$cursorfacid] = price2num(GETPOST($key)); - if (!empty($amounts[$cursorfacid])) { - $atleastonepaymentnotnull++; - if (is_numeric($amounts[$cursorfacid])) { - $totalpayment = $totalpayment + $amounts[$cursorfacid]; - } else { - setEventMessages($langs->transnoentities("InputValueIsNotAnNumber", GETPOST($key)), null, 'warnings'); - } - } - $result = $tmpinvoice->fetch($cursorfacid); - if ($result <= 0) { - dol_print_error($db); - } - $amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement()); - if ($amounts[$cursorfacid]) { - // Check amount - if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) { - $addwarning = 1; - $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier"); - } - // Check date - if ($datepaye && ($datepaye < $tmpinvoice->date)) { - $langs->load("errors"); - //$error++; - setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); - } - } - - $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => GETPOST($key)); - } elseif (substr($key, 0, 21) == 'multicurrency_amount_') { +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if (empty($reshook)) +{ + if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes')) + { + $error = 0; + + $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + $paiement_id = 0; + $totalpayment = 0; + $atleastonepaymentnotnull = 0; + + // Generate payment array and check if there is payment higher than invoice and payment date before invoice date + $tmpinvoice = new FactureFournisseur($db); + foreach ($_POST as $key => $value) + { + if (substr($key, 0, 7) == 'amount_') + { + $cursorfacid = substr($key, 7); + $amounts[$cursorfacid] = price2num(trim(GETPOST($key))); + if (!empty($amounts[$cursorfacid])) { + $atleastonepaymentnotnull++; + if (is_numeric($amounts[$cursorfacid])) { + $totalpayment = $totalpayment + $amounts[$cursorfacid]; + } else { + setEventMessages($langs->transnoentities("InputValueIsNotAnNumber", GETPOST($key)), null, 'warnings'); + } + } + $result = $tmpinvoice->fetch($cursorfacid); + if ($result <= 0) dol_print_error($db); + $amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement()); + if ($amounts[$cursorfacid]) + { + // Check amount + if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) + { + $addwarning = 1; + $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier"); + } + // Check date + if ($datepaye && ($datepaye < $tmpinvoice->date)) + { + $langs->load("errors"); + //$error++; + setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); + } + } + + $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => $_POST[$key]); + } + elseif (substr($key, 0, 21) == 'multicurrency_amount_') + { @@ -195,25 +175,24 @@ - $multicurrency_amounts[$cursorfacid] = (GETPOST($key) ? price2num(GETPOST($key)) : 0); - $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid]; - if (!empty($multicurrency_amounts[$cursorfacid])) { - $atleastonepaymentnotnull++; - } - $result = $tmpinvoice->fetch($cursorfacid); - if ($result <= 0) { - dol_print_error($db); - } - $multicurrency_amountsresttopay[$cursorfacid] = price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1)); - if ($multicurrency_amounts[$cursorfacid]) { - // Check amount - if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid]))) { - $addwarning = 1; - $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier"); - } - // Check date - if ($datepaye && ($datepaye < $tmpinvoice->date)) { - $langs->load("errors"); - //$error++; - setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); - } - } - - $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => GETPOST($key, 'int')); + $multicurrency_amounts[$cursorfacid] = price2num(trim(GETPOST($key))); + $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid]; + if (!empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++; + $result = $tmpinvoice->fetch($cursorfacid); + if ($result <= 0) dol_print_error($db); + $multicurrency_amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement(1)); + if ($multicurrency_amounts[$cursorfacid]) + { + // Check amount + if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid]))) + { + $addwarning = 1; + $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier"); + } + // Check date + if ($datepaye && ($datepaye < $tmpinvoice->date)) + { + $langs->load("errors"); + //$error++; + setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); + } + } + + $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => GETPOST($key, 'int')); @@ -221,25 +200,30 @@ - } - - // Check parameters - if (GETPOST('paiementid') <= 0) { - setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('PaymentMode')), null, 'errors'); - $error++; - } - - if (isModEnabled("banque")) { - // If bank module is on, account is required to enter a payment - if (GETPOST('accountid') <= 0) { - setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors'); - $error++; - } - } - - if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) { - setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->trans('PaymentAmount')), null, 'errors'); - $error++; - } - - if (empty($datepaye)) { - setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('Date')), null, 'errors'); - $error++; - } + } + + // Check parameters + if ($_POST['paiementid'] <= 0) + { + setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('PaymentMode')), null, 'errors'); + $error++; + } + + if (!empty($conf->banque->enabled)) + { + // If bank module is on, account is required to enter a payment + if (GETPOST('accountid') <= 0) + { + setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors'); + $error++; + } + } + + if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) + { + setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->trans('PaymentAmount')), null, 'errors'); + $error++; + } + + if (empty($datepaye)) + { + setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('Date')), null, 'errors'); + $error++; + } @@ -248 +232,2 @@ - if ($totalpayment > 0 && $multicurrency_totalpayment > 0) { + if ($totalpayment > 0 && $multicurrency_totalpayment > 0) + { @@ -250 +235 @@ - $error++; + $error++; @@ -257,5 +242,7 @@ - if ($action == 'add_paiement') { - if ($error) { - $action = 'create'; - } - // All the next of this action is displayed at the page's bottom. + if ($action == 'add_paiement') + { + if ($error) + { + $action = 'create'; + } + // Le reste propre a cette action s'affiche en bas de page. @@ -268,30 +255,28 @@ - if ($action == 'confirm_paiement' && $confirm == 'yes') { - $error = 0; - - $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); - - $multicurrency_code = array(); - $multicurrency_tx = array(); - - // Clean parameters amount if payment is for a credit note - foreach ($amounts as $key => $value) { // How payment is dispatched - $tmpinvoice = new FactureFournisseur($db); - $tmpinvoice->fetch($key); - if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) { - $newvalue = price2num($value, 'MT'); - $amounts[$key] = - abs($newvalue); - } - $multicurrency_code[$key] = $tmpinvoice->multicurrency_code; - $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx; - } - - foreach ($multicurrency_amounts as $key => $value) { // How payment is dispatched - $tmpinvoice = new FactureFournisseur($db); - $tmpinvoice->fetch($key); - if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) { - $newvalue = price2num($value, 'MT'); - $multicurrency_amounts[$key] = - abs($newvalue); - } - $multicurrency_code[$key] = $tmpinvoice->multicurrency_code; - $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx; - } + if ($action == 'confirm_paiement' && $confirm == 'yes') + { + $error = 0; + + $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); + + // Clean parameters amount if payment is for a credit note + foreach ($amounts as $key => $value) // How payment is dispatched + { + $tmpinvoice = new FactureFournisseur($db); + $tmpinvoice->fetch($key); + if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) + { + $newvalue = price2num($value, 'MT'); + $amounts[$key] = - abs($newvalue); + } + } + + foreach ($multicurrency_amounts as $key => $value) // How payment is dispatched + { + $tmpinvoice = new FactureFournisseur($db); + $tmpinvoice->fetch($key); + if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) + { + $newvalue = price2num($value, 'MT'); + $multicurrency_amounts[$key] = - abs($newvalue); + } + } @@ -300,68 +285,69 @@ - //var_dump($multicurrency_amounts); - //exit; - - if (!$error) { - $db->begin(); - - $thirdparty = new Societe($db); - if ($socid > 0) { - $thirdparty->fetch($socid); - } - - // Creation of payment line - $paiement = new PaiementFourn($db); - $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Array of amounts - $paiement->multicurrency_amounts = $multicurrency_amounts; - $paiement->multicurrency_code = $multicurrency_code; // Array with all currency of payments dispatching - $paiement->multicurrency_tx = $multicurrency_tx; // Array with all currency tx of payments dispatching - $paiement->paiementid = GETPOST('paiementid', 'int'); - $paiement->num_payment = GETPOST('num_paiement', 'alphanohtml'); - $paiement->note_private = GETPOST('comment', 'alpha'); - $paiement->fk_account = GETPOST('accountid', 'int'); - - if (!$error) { - // Create payment and update this->multicurrency_amounts if this->amounts filled or - // this->amounts if this->multicurrency_amounts filled. - // This also set ->amount and ->multicurrency_amount - $paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices') == 'on' ? 1 : 0), $thirdparty); - if ($paiement_id < 0) { - setEventMessages($paiement->error, $paiement->errors, 'errors'); - $error++; - } - } - - if (!$error) { - $result = $paiement->addPaymentToBank($user, 'payment_supplier', '(SupplierInvoicePayment)', $accountid, GETPOST('chqemetteur'), GETPOST('chqbank')); - if ($result < 0) { - setEventMessages($paiement->error, $paiement->errors, 'errors'); - $error++; - } - } - - if (!$error) { - $db->commit(); - - // If payment dispatching on more than one invoice, we stay on summary page, otherwise go on invoice card - $invoiceid = 0; - foreach ($paiement->amounts as $key => $amount) { - $facid = $key; - if (is_numeric($amount) && $amount != 0) { - if ($invoiceid != 0) { - $invoiceid = -1; // There is more than one invoice payed by this payment - } else { - $invoiceid = $facid; - } - } - } - if ($invoiceid > 0) { - $loc = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$invoiceid; - } else { - $loc = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$paiement_id; - } - header('Location: '.$loc); - exit; - } else { - $db->rollback(); - } - } + //var_dump($multicurrency_amounts); + //exit; + + if (!$error) + { + $db->begin(); + + $thirdparty = new Societe($db); + if ($socid > 0) $thirdparty->fetch($socid); + + // Creation de la ligne paiement + $paiement = new PaiementFourn($db); + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; // Array of amounts + $paiement->multicurrency_amounts = $multicurrency_amounts; + $paiement->paiementid = GETPOST('paiementid', 'int'); + + $paiement->num_payment = GETPOST('num_paiement', 'alphanohtml'); + $paiement->note_private = GETPOST('comment', 'alpha'); + $paiement->num_paiement = $paiement->num_payment; // For backward compatibility + $paiement->num_payment = $paiement->num_payment; + $paiement->note = $paiement->note_private; // For backward compatibility + $paiement->note_private = $paiement->note_private; + + if (!$error) + { + $paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices') == 'on' ? 1 : 0), $thirdparty); + if ($paiement_id < 0) + { + setEventMessages($paiement->error, $paiement->errors, 'errors'); + $error++; + } + } + + if (!$error) + { + $result = $paiement->addPaymentToBank($user, 'payment_supplier', '(SupplierInvoicePayment)', $accountid, '', ''); + if ($result < 0) + { + setEventMessages($paiement->error, $paiement->errors, 'errors'); + $error++; + } + } + + if (!$error) + { + $db->commit(); + + // If payment dispatching on more than one invoice, we stay on summary page, otherwise go on invoice card + $invoiceid = 0; + foreach ($paiement->amounts as $key => $amount) + { + $facid = $key; + if (is_numeric($amount) && $amount <> 0) + { + if ($invoiceid != 0) $invoiceid = -1; // There is more than one invoice payed by this payment + else $invoiceid = $facid; + } + } + if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$invoiceid; + else $loc = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$paiement_id; + header('Location: '.$loc); + exit; + } + else + { + $db->rollback(); + } + } @@ -384,34 +370,32 @@ -if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement') { - $object = new FactureFournisseur($db); - $result = $object->fetch($facid); - - $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); - $dateinvoice = ($datefacture == '' ? (!getDolGlobalString('MAIN_AUTOFILL_DATE') ? -1 : '') : $datefacture); - - $sql = 'SELECT s.nom as name, s.rowid as socid,'; - $sql .= ' f.rowid, f.ref, f.ref_supplier, f.total_ttc as total, f.fk_mode_reglement, f.fk_account'; - if (!$user->hasRight("societe", "client", "voir") && !$socid) { - $sql .= ", sc.fk_soc, sc.fk_user "; - } - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn as f'; - if (!$user->hasRight("societe", "client", "voir") && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } - $sql .= ' WHERE f.fk_soc = s.rowid'; - $sql .= ' AND f.rowid = '.((int) $facid); - if (!$user->hasRight("societe", "client", "voir") && !$socid) { - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); - } - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - if ($num) { - $obj = $db->fetch_object($resql); - $total = $obj->total; - - print load_fiche_titre($langs->trans('DoPayment')); - - // Add realtime total information - if (!empty($conf->use_javascript_ajax)) { - print "\n".''."\n"; - } - - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print dol_get_fiche_head(null); - - print ''; - - print ''; - - print ''; - print ''; - if (isModEnabled("banque")) { - print ''; - } else { - print ''; - } - print ''; - print ''; - print ''; - print '
'.$langs->trans('Company').''; - $supplierstatic->id = $obj->socid; - $supplierstatic->name = $obj->name; - print $supplierstatic->getNomUrl(1, 'supplier'); - print '
'.$langs->trans('Date').''; - // $object is default vendor invoice - $adddateof = array(array('adddateof'=>$object->date)); - $adddateof[] = array('adddateof'=>$object->date_echeance, 'labeladddateof'=>$langs->transnoentities('DateDue')); - print $form->selectDate($dateinvoice, '', '', '', 0, "addpaiement", 1, 1, 0, '', '', $adddateof); - print '
'.$langs->trans('PaymentMode').''; - $form->select_types_paiements(!GETPOST('paiementid') ? $obj->fk_mode_reglement : GETPOST('paiementid'), 'paiementid'); - print '
'.$langs->trans('Account').''; - print img_picto('', 'bank_account', 'class="pictofixedwidth"'); - print $form->select_comptes(empty($accountid) ? $obj->fk_account : $accountid, 'accountid', 0, '', 2, '', 0, 'widthcentpercentminusx maxwidth500', 1); - print '
 
'.$langs->trans('Numero').'
'.$langs->trans('Comments').''; - print '
'; - print dol_get_fiche_end(); + print ' });'."\n"; + + print ' '."\n"; + } + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + dol_fiche_head(null); + + print ''; + + print ''; + print ''; + print ''; + if (!empty($conf->banque->enabled)) + { + print ''; + } + else + { + print ''; + } + print ''; + print ''; + print ''; + print '
'.$langs->trans('Company').''; + $supplierstatic->id = $obj->socid; + $supplierstatic->name = $obj->name; + print $supplierstatic->getNomUrl(1, 'supplier'); + print '
'.$langs->trans('Date').''; + print $form->selectDate($dateinvoice, '', '', '', 0, "addpaiement", 1, 1, 0, '', '', $object->date); + print '
'.$langs->trans('PaymentMode').''; + $form->select_types_paiements(empty($_POST['paiementid']) ? $obj->fk_mode_reglement : $_POST['paiementid'], 'paiementid'); + print '
'.$langs->trans('Account').''; + $form->select_comptes(empty($accountid) ? $obj->fk_account : $accountid, 'accountid', 0, '', 2); + print '
 
'.$langs->trans('Numero').'
'.$langs->trans('Comments').''; + print '
'; + dol_fiche_end(); @@ -535,3 +515,3 @@ - $error = $hookmanager->error; - $errors = $hookmanager->errors; - if (empty($reshook)) { + $error = $hookmanager->error; $errors = $hookmanager->errors; + if (empty($reshook)) + { @@ -539,32 +519,35 @@ - * All unpaid supplier invoices - */ - $sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.type, f.total_ht, f.total_ttc,'; - $sql .= ' f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,'; - $sql .= ' f.datef as df, f.date_lim_reglement as dlr,'; - $sql .= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; - $sql .= " WHERE f.entity = ".((int) $conf->entity); - $sql .= ' AND f.fk_soc = '.((int) $object->socid); - $sql .= ' AND f.paye = 0'; - $sql .= ' AND f.fk_statut = 1'; // Status=0 => unvalidated, Status=2 => canceled - if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE) { - $sql .= ' AND f.type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation - } else { - $sql .= ' AND f.type = 2'; // If paying back a credit note, we show all credit notes - } - // Group by because we have a total - $sql .= ' GROUP BY f.datef, f.ref, f.ref_supplier, f.rowid, f.type, f.total_ht, f.total_ttc,'; - $sql .= ' f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,'; - $sql .= ' f.datef, f.date_lim_reglement'; - // Sort invoices by date and serial number: the older one comes first - $sql .= ' ORDER BY f.datef ASC, f.ref ASC'; - - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - if ($num > 0) { - $i = 0; - print '
'; - - if (!empty($conf->use_javascript_ajax)) { + * All unpayed supplier invoices + */ + $sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.type, f.total_ht, f.total_ttc,'; + $sql .= ' f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,'; + $sql .= ' f.datef as df, f.date_lim_reglement as dlr,'; + $sql .= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; + $sql .= " WHERE f.entity = ".$conf->entity; + $sql .= ' AND f.fk_soc = '.$object->socid; + $sql .= ' AND f.paye = 0'; + $sql .= ' AND f.fk_statut = 1'; // Statut=0 => non validee, Statut=2 => annulee + if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE) + { + $sql .= ' AND f.type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation + } + else + { + $sql .= ' AND f.type = 2'; // If paying back a credit note, we show all credit notes + } + // Group by because we have a total + $sql .= ' GROUP BY f.datef, f.ref, f.ref_supplier, f.rowid, f.type, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef, f.date_lim_reglement'; + // Sort invoices by date and serial number: the older one comes first + $sql .= ' ORDER BY f.datef ASC, f.ref ASC'; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num > 0) + { + $i = 0; + print '
'; + + if (!empty($conf->use_javascript_ajax)) { @@ -572 +555 @@ - print "\n".'