code syntax fourn directory

This commit is contained in:
Frédéric FRANCE 2021-02-25 23:21:30 +01:00
parent f7c119e48c
commit ed6d2376f1
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
38 changed files with 5080 additions and 4374 deletions

View File

@ -22,10 +22,18 @@
* \brief File to return an Ajax response to get list of possible prices for margin calculation
*/
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1'); // Disables token renewal
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
if (!defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
@ -46,47 +54,45 @@ top_httphead();
//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
if ($idprod > 0)
{
if ($idprod > 0) {
$producttmp = new ProductFournisseur($db);
$producttmp->fetch($idprod);
$sorttouse = 's.nom, pfp.quantity, pfp.price';
if (GETPOST('bestpricefirst')) $sorttouse = 'pfp.unitprice, s.nom, pfp.quantity, pfp.price';
if (GETPOST('bestpricefirst')) {
$sorttouse = 'pfp.unitprice, s.nom, pfp.quantity, pfp.price';
}
$productSupplierArray = $producttmp->list_product_fournisseur_price($idprod, $sorttouse); // We list all price per supplier, and then firstly with the lower quantity. So we can choose first one with enough quantity into list.
if (is_array($productSupplierArray))
{
foreach ($productSupplierArray as $productSupplier)
{
if (is_array($productSupplierArray)) {
foreach ($productSupplierArray as $productSupplier) {
$price = $productSupplier->fourn_price * (1 - $productSupplier->fourn_remise_percent / 100);
$unitprice = $productSupplier->fourn_unitprice * (1 - $productSupplier->fourn_remise_percent / 100);
$title = $productSupplier->fourn_name.' - '.$productSupplier->fourn_ref.' - ';
if ($productSupplier->fourn_qty == 1)
{
if ($productSupplier->fourn_qty == 1) {
$title .= price($price, 0, $langs, 0, 0, -1, $conf->currency)."/";
}
$title .= $productSupplier->fourn_qty.' '.($productSupplier->fourn_qty == 1 ? $langs->trans("Unit") : $langs->trans("Units"));
if ($productSupplier->fourn_qty > 1)
{
if ($productSupplier->fourn_qty > 1) {
$title .= " - ";
$title .= price($unitprice, 0, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit");
$price = $unitprice;
}
$label = price($price, 0, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit");
if ($productSupplier->fourn_ref) $label .= ' ('.$productSupplier->fourn_ref.')';
if ($productSupplier->fourn_ref) {
$label .= ' ('.$productSupplier->fourn_ref.')';
}
$prices[] = array("id" => $productSupplier->product_fourn_price_id, "price" => price2num($price, 0, '', 0), "label" => $label, "title" => $title); // For price field, we must use price2num(), for label or title, price()
}
}
// After best supplier prices and before costprice
if (!empty($conf->stock->enabled))
{
if (!empty($conf->stock->enabled)) {
// Add price for pmp
$price = $producttmp->pmp;
$prices[] = array("id" => 'pmpprice', "price" => price2num($price), "label" => $langs->trans("PMPValueShort").': '.price($price, 0, $langs, 0, 0, -1, $conf->currency), "title" => $langs->trans("PMPValueShort").': '.price($price, 0, $langs, 0, 0, -1, $conf->currency)); // For price field, we must use price2num(), for label or title, price()

View File

@ -35,8 +35,12 @@ require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
if (!empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
if (!empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
if (!empty($conf->adherent->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
}
if (!empty($conf->categorie->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
}
// Load translation files required by page
$langs->loadLangs(array(
@ -53,7 +57,9 @@ $cancelbutton = GETPOST('cancel', 'alpha');
// Security check
$id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int'));
if ($user->socid) $id = $user->socid;
if ($user->socid) {
$id = $user->socid;
}
$result = restrictedArea($user, 'societe&fournisseur', $id, '&societe', '', 'rowid');
$object = new Fournisseur($db);
@ -81,44 +87,48 @@ if ($object->id > 0) {
$parameters = array('id'=>$id);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook))
{
if ($cancelbutton)
{
if (empty($reshook)) {
if ($cancelbutton) {
$action = "";
}
if ($action == 'setsupplieraccountancycode')
{
if ($action == 'setsupplieraccountancycode') {
$result = $object->fetch($id);
$object->code_compta_fournisseur = $_POST["supplieraccountancycode"];
$object->code_compta_fournisseur = $_POST["supplieraccountancycode"];
$result = $object->update($object->id, $user, 1, 0, 1);
if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
// terms of the settlement
if ($action == 'setconditions' && $user->rights->societe->creer)
{
if ($action == 'setconditions' && $user->rights->societe->creer) {
$object->fetch($id);
$result = $object->setPaymentTerms(GETPOST('cond_reglement_supplier_id', 'int'));
if ($result < 0) dol_print_error($db, $object->error);
if ($result < 0) {
dol_print_error($db, $object->error);
}
}
// mode de reglement
if ($action == 'setmode' && $user->rights->societe->creer)
{
if ($action == 'setmode' && $user->rights->societe->creer) {
$object->fetch($id);
$result = $object->setPaymentMethods(GETPOST('mode_reglement_supplier_id', 'int'));
if ($result < 0) dol_print_error($db, $object->error);
if ($result < 0) {
dol_print_error($db, $object->error);
}
}
// update supplier order min amount
if ($action == 'setsupplier_order_min_amount')
{
if ($action == 'setsupplier_order_min_amount') {
$object->fetch($id);
$object->supplier_order_min_amount = price2num(GETPOST('supplier_order_min_amount', 'alpha'));
$result = $object->update($object->id, $user);
if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
if ($action == 'update_extras') {
@ -129,15 +139,20 @@ if (empty($reshook))
// Fill array 'array_options' with data from update form
$ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
if ($ret < 0) $error++;
if (!$error)
{
$result = $object->insertExtraFields('COMPANY_MODIFY');
if ($result < 0) $error++;
if ($ret < 0) {
$error++;
}
if ($error) $action = 'edit_extras';
if (!$error) {
$result = $object->insertExtraFields('COMPANY_MODIFY');
if ($result < 0) {
$error++;
}
}
if ($error) {
$action = 'edit_extras';
}
}
}
@ -149,17 +164,19 @@ if (empty($reshook))
$contactstatic = new Contact($db);
$form = new Form($db);
if ($id > 0 && empty($object->id))
{
if ($id > 0 && empty($object->id)) {
// Load data of third party
$res = $object->fetch($id);
if ($object->id <= 0) dol_print_error($db, $object->error);
if ($object->id <= 0) {
dol_print_error($db, $object->error);
}
}
if ($object->id > 0)
{
if ($object->id > 0) {
$title = $langs->trans("ThirdParty")." - ".$langs->trans('Supplier');
if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name." - ".$langs->trans('Supplier');
if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
$title = $object->name." - ".$langs->trans('Supplier');
}
$help_url = '';
llxHeader('', $title, $help_url);
@ -184,22 +201,20 @@ if ($object->id > 0)
print $object->getTypeUrl(1);
print '</td></tr>';
if (!empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
{
if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
}
if ($object->fournisseur)
{
if ($object->fournisseur) {
print '<tr>';
print '<td class="titlefield">'.$langs->trans("SupplierCode").'</td><td>';
print $object->code_fournisseur;
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td>';
print '</tr>';
print '<td class="titlefield">'.$langs->trans("SupplierCode").'</td><td>';
print $object->code_fournisseur;
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td>';
print '</tr>';
$langs->load('compta');
print '<tr>';
@ -221,14 +236,12 @@ if ($object->id > 0)
print '</tr>';
// Local Taxes
if ($mysoc->useLocalTax(1))
{
if ($mysoc->useLocalTax(1)) {
print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
print yn($object->localtax1_assuj);
print '</td></tr>';
}
if ($mysoc->useLocalTax(2))
{
if ($mysoc->useLocalTax(2)) {
print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
print yn($object->localtax2_assuj);
print '</td></tr>';
@ -246,11 +259,12 @@ if ($object->id > 0)
print '<table width="100%" class="nobordernopadding"><tr><td>';
print $langs->trans('PaymentConditions');
print '<td>';
if (($action != 'editconditions') && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
if (($action != 'editconditions') && $user->rights->societe->creer) {
print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td>';
if ($action == 'editconditions')
{
if ($action == 'editconditions') {
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_supplier_id, 'cond_reglement_supplier_id', -1, 1);
} else {
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_supplier_id, 'none');
@ -263,11 +277,12 @@ if ($object->id > 0)
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
print $langs->trans('PaymentMode');
print '<td>';
if (($action != 'editmode') && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
if (($action != 'editmode') && $user->rights->societe->creer) {
print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td>';
if ($action == 'editmode')
{
if ($action == 'editmode') {
$form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_supplier_id, 'mode_reglement_supplier_id', 'DBIT', 1, 1);
} else {
$form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_supplier_id, 'none');
@ -280,8 +295,7 @@ if ($object->id > 0)
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
print $langs->trans("CustomerRelativeDiscountShort");
print '<td><td class="right">';
if ($user->rights->societe->creer && !$user->socid > 0)
{
if ($user->rights->societe->creer && !$user->socid > 0) {
print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
}
print '</td></tr></table>';
@ -294,22 +308,24 @@ if ($object->id > 0)
print '<tr><td class="nowrap">';
print $langs->trans("CustomerAbsoluteDiscountShort");
print '<td><td class="right">';
if ($user->rights->societe->creer && !$user->socid > 0)
{
if ($user->rights->societe->creer && !$user->socid > 0) {
print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.img_edit($langs->trans("Modify")).'</a>';
}
print '</td></tr></table>';
print '</td>';
print '<td>';
$amount_discount = $object->getAvailableDiscounts('', '', 0, 1);
if ($amount_discount < 0) dol_print_error($db, $object->error);
if ($amount_discount > 0) print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.price($amount_discount, 1, $langs, 1, -1, -1, $conf->currency).'</a>';
if ($amount_discount < 0) {
dol_print_error($db, $object->error);
}
if ($amount_discount > 0) {
print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.price($amount_discount, 1, $langs, 1, -1, -1, $conf->currency).'</a>';
}
//else print $langs->trans("DiscountNone");
print '</td>';
print '</tr>';
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT))
{
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)) {
print '<tr class="nowrap">';
print '<td>';
print $form->editfieldkey("OrderMinAmount", 'supplier_order_min_amount', $object->supplier_order_min_amount, $object, $user->rights->societe->creer);
@ -321,8 +337,7 @@ if ($object->id > 0)
}
// Categories
if (!empty($conf->categorie->enabled))
{
if (!empty($conf->categorie->enabled)) {
$langs->load("categories");
print '<tr><td>'.$langs->trans("SuppliersCategoriesShort").'</td>';
print '<td>';
@ -335,16 +350,14 @@ if ($object->id > 0)
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
// Module Adherent
if (!empty($conf->adherent->enabled))
{
if (!empty($conf->adherent->enabled)) {
$langs->load("members");
$langs->load("users");
print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
print '<td>';
$adh = new Adherent($db);
$result = $adh->fetch('', '', $object->id);
if ($result > 0)
{
if ($result > 0) {
$adh->ref = $adh->getFullName($langs);
print $adh->getNomUrl(1);
} else {
@ -371,8 +384,7 @@ if ($object->id > 0)
$boxstat .= '<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="border boxtable boxtablenobottom boxtablenotop" width="100%">';
$boxstat .= '<tr class="impair nohover"><td colspan="2" class="tdboxstats nohover">';
if ($conf->supplier_proposal->enabled)
{
if ($conf->supplier_proposal->enabled) {
// Box proposals
$tmp = $object->getOutstandingProposals('supplier');
$outstandingOpened = $tmp['opened'];
@ -381,16 +393,19 @@ if ($object->id > 0)
$text = $langs->trans("OverAllSupplierProposals");
$link = DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->id;
$icon = 'bill';
if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
if ($link) {
$boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
}
$boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
$boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
$boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
$boxstat .= '</div>';
if ($link) $boxstat .= '</a>';
if ($link) {
$boxstat .= '</a>';
}
}
if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))
{
if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
// Box proposals
$tmp = $object->getOutstandingOrders('supplier');
$outstandingOpened = $tmp['opened'];
@ -399,16 +414,19 @@ if ($object->id > 0)
$text = $langs->trans("OverAllOrders");
$link = DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id;
$icon = 'bill';
if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
if ($link) {
$boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
}
$boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
$boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
$boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
$boxstat .= '</div>';
if ($link) $boxstat .= '</a>';
if ($link) {
$boxstat .= '</a>';
}
}
if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))
{
if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
$tmp = $object->getOutstandingBills('supplier');
$outstandingOpened = $tmp['opened'];
$outstandingTotal = $tmp['total_ht'];
@ -417,23 +435,31 @@ if ($object->id > 0)
$text = $langs->trans("OverAllInvoices");
$link = DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->id;
$icon = 'bill';
if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
if ($link) {
$boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
}
$boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
$boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
$boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
$boxstat .= '</div>';
if ($link) $boxstat .= '</a>';
if ($link) {
$boxstat .= '</a>';
}
// Box outstanding bill
$text = $langs->trans("CurrentOutstandingBill");
$link = DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id;
$icon = 'bill';
if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
if ($link) {
$boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
}
$boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
$boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
$boxstat .= '<span class="boxstatsindicator'.($outstandingOpened > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
$boxstat .= '</div>';
if ($link) $boxstat .= '</a>';
if ($link) {
$boxstat .= '</a>';
}
$tmp = $object->getOutstandingBills('supplier', 1);
$outstandingOpenedLate = $tmp['opened'];
@ -441,12 +467,16 @@ if ($object->id > 0)
$text = $langs->trans("CurrentOutstandingBillLate");
$link = DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id;
$icon = 'bill';
if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
if ($link) {
$boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
}
$boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
$boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
$boxstat .= '<span class="boxstatsindicator'.($outstandingOpenedLate > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpenedLate, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
$boxstat .= '</div>';
if ($link) $boxstat .= '</a>';
if ($link) {
$boxstat .= '</a>';
}
}
}
@ -468,13 +498,12 @@ if ($object->id > 0)
print '</tr>';
print '</table>';
print '<br>';
*/
*/
/*
* List of products
*/
if (!empty($conf->product->enabled) || !empty($conf->service->enabled))
{
if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
$langs->load("products");
//Query from product/liste.php
$sql = 'SELECT p.rowid, p.ref, p.label, p.fk_product_type, p.entity,';
@ -487,7 +516,9 @@ if ($object->id > 0)
$sql .= $db->plimit($MAXLIST);
$query = $db->query($sql);
if (!$query) dol_print_error($db);
if (!$query) {
dol_print_error($db);
}
$num = $db->num_rows($query);
@ -498,12 +529,10 @@ if ($object->id > 0)
print '</a></td></tr>';
$return = array();
if ($num > 0)
{
if ($num > 0) {
$productstatic = new Product($db);
while ($objp = $db->fetch_object($query))
{
while ($objp = $db->fetch_object($query)) {
$productstatic->id = $objp->rowid;
$productstatic->ref = $objp->ref;
$productstatic->label = $objp->label;
@ -523,11 +552,9 @@ if ($object->id > 0)
//print '<td class="right" class="nowrap">'.dol_print_date($objp->tms, 'day').'</td>';
print '<td class="right">';
//print (isset($objp->unitprice) ? price($objp->unitprice) : '');
if (isset($objp->price))
{
if (isset($objp->price)) {
print price($objp->price);
if ($objp->quantity > 1)
{
if ($objp->quantity > 1) {
print ' / ';
print $objp->quantity;
}
@ -546,8 +573,7 @@ if ($object->id > 0)
*/
$proposalstatic = new SupplierProposal($db);
if ($user->rights->supplier_proposal->lire)
{
if ($user->rights->supplier_proposal->lire) {
$langs->loadLangs(array("supplier_proposal"));
$sql = "SELECT p.rowid, p.ref, p.date_valid as dc, p.fk_statut, p.total_ht, p.total_tva, p.total_ttc";
@ -558,13 +584,11 @@ if ($object->id > 0)
$sql .= " ".$db->plimit($MAXLIST);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
if ($num > 0)
{
if ($num > 0) {
print '<table class="noborder centpercent lastrecordtable">';
print '<tr class="liste_titre">';
@ -576,8 +600,7 @@ if ($object->id > 0)
print '</td></tr>';
}
while ($i < $num && $i <= $MAXLIST)
{
while ($i < $num && $i <= $MAXLIST) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
@ -590,8 +613,7 @@ if ($object->id > 0)
print $proposalstatic->getNomUrl(1);
print '</td>';
print '<td class="center" width="80">';
if ($obj->dc)
{
if ($obj->dc) {
print dol_print_date($db->jdate($obj->dc), 'day');
} else {
print "-";
@ -603,7 +625,9 @@ if ($object->id > 0)
}
$db->free($resql);
if ($num > 0) print "</table>";
if ($num > 0) {
print "</table>";
}
} else {
dol_print_error($db);
}
@ -614,8 +638,7 @@ if ($object->id > 0)
*/
$orderstatic = new CommandeFournisseur($db);
if ($user->rights->fournisseur->commande->lire)
{
if ($user->rights->fournisseur->commande->lire) {
// TODO move to DAO class
// Check if there are supplier orders billable
$sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_supplier,';
@ -626,8 +649,7 @@ if ($object->id > 0)
$sql2 .= " AND c.entity IN (".getEntity('commande_fournisseur').")";
$sql2 .= ' AND s.rowid = '.$object->id;
// Show orders we can bill
if (empty($conf->global->SUPPLIER_ORDER_TO_INVOICE_STATUS))
{
if (empty($conf->global->SUPPLIER_ORDER_TO_INVOICE_STATUS)) {
$sql2 .= " AND c.fk_statut IN (".$db->sanitize(CommandeFournisseur::STATUS_RECEIVED_COMPLETELY).")"; // Must match filter in htdocs/fourn/commande/list.php
} else {
// CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.", ".CommandeFournisseur::STATUS_RECEIVED_COMPLETELY
@ -651,8 +673,7 @@ if ($object->id > 0)
$sql .= " WHERE p.fk_soc =".$object->id;
$sql .= " AND p.entity IN (".getEntity('commande_fournisseur').")";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$object_count = $db->fetch_object($resql);
$num = $object_count->total;
}
@ -664,12 +685,10 @@ if ($object->id > 0)
$sql .= " ORDER BY p.date_commande DESC";
$sql .= " ".$db->plimit($MAXLIST);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$i = 0;
if ($num > 0)
{
if ($num > 0) {
print '<table class="noborder centpercent lastrecordtable">';
print '<tr class="liste_titre">';
@ -681,8 +700,7 @@ if ($object->id > 0)
print '</td></tr>';
}
while ($i < $num && $i < $MAXLIST)
{
while ($i < $num && $i < $MAXLIST) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
@ -695,8 +713,7 @@ if ($object->id > 0)
print $orderstatic->getNomUrl(1);
print '</td>';
print '<td class="center" width="80">';
if ($obj->dc)
{
if ($obj->dc) {
print dol_print_date($db->jdate($obj->dc), 'day');
} else {
print "-";
@ -708,7 +725,9 @@ if ($object->id > 0)
}
$db->free($resql);
if ($num > 0) print "</table>";
if ($num > 0) {
print "</table>";
}
} else {
dol_print_error($db);
}
@ -721,8 +740,7 @@ if ($object->id > 0)
$langs->load('bills');
$facturestatic = new FactureFournisseur($db);
if ($user->rights->fournisseur->facture->lire)
{
if ($user->rights->fournisseur->facture->lire) {
// TODO move to DAO class
$sql = 'SELECT f.rowid, f.libelle as label, f.ref, f.ref_supplier, f.fk_statut, f.datef as df, f.total_ht, f.total_tva, f.total_ttc as amount,f.paye,';
$sql .= ' SUM(pf.amount) as am';
@ -733,12 +751,10 @@ if ($object->id > 0)
$sql .= ' GROUP BY f.rowid,f.libelle,f.ref,f.ref_supplier,f.fk_statut,f.datef,f.total_ht,f.total_tva,f.total_ttc,f.paye';
$sql .= ' ORDER BY f.datef DESC';
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
if ($num > 0)
{
if ($num > 0) {
print '<table class="noborder centpercent lastrecordtable">';
print '<tr class="liste_titre">';
@ -749,8 +765,7 @@ if ($object->id > 0)
print '</td></tr>';
}
while ($i < min($num, $MAXLIST))
{
while ($i < min($num, $MAXLIST)) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
@ -777,7 +792,9 @@ if ($object->id > 0)
$i++;
}
$db->free($resql);
if ($num > 0) print '</table>';
if ($num > 0) {
print '</table>';
}
} else {
dol_print_error($db);
}
@ -797,15 +814,12 @@ if ($object->id > 0)
$parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
// modified by hook
if (empty($reshook))
{
if ($object->status != 1)
{
if (empty($reshook)) {
if ($object->status != 1) {
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
}
if ($conf->supplier_proposal->enabled && $user->rights->supplier_proposal->creer)
{
if ($conf->supplier_proposal->enabled && $user->rights->supplier_proposal->creer) {
$langs->load("supplier_proposal");
if ($object->status == 1) {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/supplier_proposal/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddSupplierProposal").'</a>';
@ -814,8 +828,7 @@ if ($object->id > 0)
}
}
if ($user->rights->fournisseur->commande->creer)
{
if ($user->rights->fournisseur->commande->creer) {
$langs->load("orders");
if ($object->status == 1) {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddOrder").'</a>';
@ -824,21 +837,20 @@ if ($object->id > 0)
}
}
if ($user->rights->fournisseur->facture->creer)
{
if (!empty($orders2invoice) && $orders2invoice > 0)
{
if ($user->rights->fournisseur->facture->creer) {
if (!empty($orders2invoice) && $orders2invoice > 0) {
if ($object->status == 1) {
// Company is open
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id.'&search_billed=0&autoselectall=1">'.$langs->trans("CreateInvoiceForThisSupplier").'</a></div>';
} else {
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
}
} else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice").' ('.$langs->trans("WithReceptionFinished").')').'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
} else {
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice").' ('.$langs->trans("WithReceptionFinished").')').'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
}
}
if ($user->rights->fournisseur->facture->creer)
{
if ($user->rights->fournisseur->facture->creer) {
$langs->load("bills");
if ($object->status == 1) {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a>';
@ -848,10 +860,8 @@ if ($object->id > 0)
}
// Add action
if (!empty($conf->agenda->enabled) && !empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status == 1)
{
if ($user->rights->agenda->myactions->create)
{
if (!empty($conf->agenda->enabled) && !empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status == 1) {
if ($user->rights->agenda->myactions->create) {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a>';
} else {
print '<a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a>';
@ -862,15 +872,13 @@ if ($object->id > 0)
print '</div>';
if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
{
if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD)) {
print '<br>';
// List of contacts
show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
}
if (!empty($conf->global->MAIN_REPEATTASKONEACHTAB))
{
if (!empty($conf->global->MAIN_REPEATTASKONEACHTAB)) {
print load_fiche_titre($langs->trans("ActionsOnCompany"), '', '');
// List of todo actions

View File

@ -34,7 +34,7 @@ class SupplierInvoices extends DolibarrApi
*
* @var array $FIELDS Mandatory fields, checked when create and update object
*/
static $FIELDS = array(
public static $FIELDS = array(
'socid',
);
@ -109,20 +109,32 @@ class SupplierInvoices extends DolibarrApi
// If the internal user must only see his customers, force searching by him
$search_sale = 0;
if (!DolibarrApiAccess::$user->rights->societe->client->voir) $search_sale = DolibarrApiAccess::$user->id;
if (!DolibarrApiAccess::$user->rights->societe->client->voir) {
$search_sale = DolibarrApiAccess::$user->id;
}
$sql = "SELECT t.rowid";
// We need these fields in order to filter by sale (including the case where the user can only see his prospects)
if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user";
if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) {
$sql .= ", sc.fk_soc, sc.fk_user";
}
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as t";
// We need this table joined to the select in order to filter by sale
if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= ' WHERE t.entity IN ('.getEntity('supplier_invoice').')';
if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc";
if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")";
if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) {
$sql .= " AND t.fk_soc = sc.fk_soc";
}
if ($socids) {
$sql .= " AND t.fk_soc IN (".$socids.")";
}
if ($search_sale > 0) {
$sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
}
// Filter by status
if ($status == 'draft') {
@ -142,10 +154,8 @@ class SupplierInvoices extends DolibarrApi
$sql .= " AND sc.fk_user = ".$search_sale;
}
// Add sql filters
if ($sqlfilters)
{
if (!DolibarrApi::_checkFilters($sqlfilters))
{
if ($sqlfilters) {
if (!DolibarrApi::_checkFilters($sqlfilters)) {
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -154,8 +164,7 @@ class SupplierInvoices extends DolibarrApi
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0)
{
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
@ -168,8 +177,7 @@ class SupplierInvoices extends DolibarrApi
$i = 0;
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
while ($i < $min)
{
while ($i < $min) {
$obj = $this->db->fetch_object($result);
$invoice_static = new FactureFournisseur($this->db);
if ($invoice_static->fetch($obj->rowid)) {
@ -244,12 +252,15 @@ class SupplierInvoices extends DolibarrApi
}
foreach ($request_data as $field => $value) {
if ($field == 'id') continue;
if ($field == 'id') {
continue;
}
$this->invoice->$field = $value;
}
if ($this->invoice->update($id, DolibarrApiAccess::$user))
if ($this->invoice->update($id, DolibarrApiAccess::$user)) {
return $this->get($id);
}
return false;
}
@ -279,8 +290,7 @@ class SupplierInvoices extends DolibarrApi
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if ($this->invoice->delete(DolibarrApiAccess::$user) < 0)
{
if ($this->invoice->delete(DolibarrApiAccess::$user) < 0) {
throw new RestException(500);
}
@ -459,16 +469,14 @@ class SupplierInvoices extends DolibarrApi
$paiement->note_public = $comment;
$paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices
if ($paiement_id < 0)
{
if ($paiement_id < 0) {
$this->db->rollback();
throw new RestException(400, 'Payment error : '.$paiement->error);
}
if (!empty($conf->banque->enabled)) {
$result = $paiement->addPaymentToBank(DolibarrApiAccess::$user, 'payment_supplier', '(SupplierInvoicePayment)', $accountid, $chqemetteur, $chqbank);
if ($result < 0)
{
if ($result < 0) {
$this->db->rollback();
throw new RestException(400, 'Add payment to bank error : '.$paiement->error);
}
@ -706,8 +714,9 @@ class SupplierInvoices extends DolibarrApi
{
$invoice = array();
foreach (SupplierInvoices::$FIELDS as $field) {
if (!isset($data[$field]))
if (!isset($data[$field])) {
throw new RestException(400, "$field field missing");
}
$invoice[$field] = $data[$field];
}
return $invoice;

View File

@ -32,7 +32,7 @@ class SupplierOrders extends DolibarrApi
*
* @var array $FIELDS Mandatory fields, checked when create and update object
*/
static $FIELDS = array(
public static $FIELDS = array(
'socid'
);
@ -108,41 +108,70 @@ class SupplierOrders extends DolibarrApi
// If the internal user must only see his customers, force searching by him
$search_sale = 0;
if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
$search_sale = DolibarrApiAccess::$user->id;
}
$sql = "SELECT t.rowid";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
$sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
}
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as t";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
}
if (!empty($product_ids)) $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; // We need this table joined to the select in order to filter by product
if (!empty($product_ids)) {
$sql .= ", ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; // We need this table joined to the select in order to filter by product
}
$sql .= ' WHERE t.entity IN ('.getEntity('supplier_order').')';
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc";
if (!empty($product_ids)) $sql .= " AND cd.fk_commande = t.rowid AND cd.fk_product IN (".$product_ids.")";
if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")";
if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
$sql .= " AND t.fk_soc = sc.fk_soc";
}
if (!empty($product_ids)) {
$sql .= " AND cd.fk_commande = t.rowid AND cd.fk_product IN (".$product_ids.")";
}
if ($socids) {
$sql .= " AND t.fk_soc IN (".$socids.")";
}
if ($search_sale > 0) {
$sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
}
// Filter by status
if ($status == 'draft') $sql .= " AND t.fk_statut IN (0)";
if ($status == 'validated') $sql .= " AND t.fk_statut IN (1)";
if ($status == 'approved') $sql .= " AND t.fk_statut IN (2)";
if ($status == 'running') $sql .= " AND t.fk_statut IN (3)";
if ($status == 'received_start') $sql .= " AND t.fk_statut IN (4)";
if ($status == 'received_end') $sql .= " AND t.fk_statut IN (5)";
if ($status == 'cancelled') $sql .= " AND t.fk_statut IN (6,7)";
if ($status == 'refused') $sql .= " AND t.fk_statut IN (9)";
if ($status == 'draft') {
$sql .= " AND t.fk_statut IN (0)";
}
if ($status == 'validated') {
$sql .= " AND t.fk_statut IN (1)";
}
if ($status == 'approved') {
$sql .= " AND t.fk_statut IN (2)";
}
if ($status == 'running') {
$sql .= " AND t.fk_statut IN (3)";
}
if ($status == 'received_start') {
$sql .= " AND t.fk_statut IN (4)";
}
if ($status == 'received_end') {
$sql .= " AND t.fk_statut IN (5)";
}
if ($status == 'cancelled') {
$sql .= " AND t.fk_statut IN (6,7)";
}
if ($status == 'refused') {
$sql .= " AND t.fk_statut IN (9)";
}
// Insert sale filter
if ($search_sale > 0)
{
if ($search_sale > 0) {
$sql .= " AND sc.fk_user = ".$search_sale;
}
// Add sql filters
if ($sqlfilters)
{
if (!DolibarrApi::_checkFilters($sqlfilters))
{
if ($sqlfilters) {
if (!DolibarrApi::_checkFilters($sqlfilters)) {
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -151,8 +180,7 @@ class SupplierOrders extends DolibarrApi
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0)
{
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
@ -161,13 +189,11 @@ class SupplierOrders extends DolibarrApi
}
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$i = 0;
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
while ($i < $min)
{
while ($i < $min) {
$obj = $this->db->fetch_object($result);
$order_static = new CommandeFournisseur($this->db);
if ($order_static->fetch($obj->rowid)) {
@ -207,13 +233,13 @@ class SupplierOrders extends DolibarrApi
$this->order->date = dol_now();
}
/* We keep lines as an array
if (isset($request_data["lines"])) {
$lines = array();
foreach ($request_data["lines"] as $line) {
array_push($lines, (object) $line);
}
$this->order->lines = $lines;
}*/
if (isset($request_data["lines"])) {
$lines = array();
foreach ($request_data["lines"] as $line) {
array_push($lines, (object) $line);
}
$this->order->lines = $lines;
}*/
if ($this->order->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating order", array_merge(array($this->order->error), $this->order->errors));
@ -244,12 +270,15 @@ class SupplierOrders extends DolibarrApi
}
foreach ($request_data as $field => $value) {
if ($field == 'id') continue;
if ($field == 'id') {
continue;
}
$this->order->$field = $value;
}
if ($this->order->update($id, DolibarrApiAccess::$user))
if ($this->order->update($id, DolibarrApiAccess::$user)) {
return $this->get($id);
}
return false;
}
@ -368,8 +397,9 @@ class SupplierOrders extends DolibarrApi
{
$order = array();
foreach (SupplierOrders::$FIELDS as $field) {
if (!isset($data[$field]))
if (!isset($data[$field])) {
throw new RestException(400, "$field field missing");
}
$order[$field] = $data[$field];
}
return $order;

View File

@ -62,12 +62,10 @@ class Fournisseur extends Societe
$sql .= " WHERE cf.fk_soc = ".$this->id;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
if ($num == 1)
{
if ($num == 1) {
$row = $this->db->fetch_row($resql);
$this->single_open_commande = $row[0];
@ -91,8 +89,7 @@ class Fournisseur extends Societe
$sql .= " AND pfp.fk_soc = ".$this->id;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $this->db->fetch_object($resql);
return $obj->nb;
} else {
@ -116,8 +113,7 @@ class Fournisseur extends Societe
$sql = "SELECT count(s.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$user->socid)
{
if (!$user->rights->societe->client->voir && !$user->socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
$sql .= " WHERE sc.fk_user = ".$user->id;
$clause = "AND";
@ -126,10 +122,8 @@ class Fournisseur extends Societe
$sql .= " AND s.entity IN (".getEntity('societe').")";
$resql = $this->db->query($sql);
if ($resql)
{
while ($obj = $this->db->fetch_object($resql))
{
if ($resql) {
while ($obj = $this->db->fetch_object($resql)) {
$this->nb["suppliers"] = $obj->nb;
}
$this->db->free($resql);
@ -158,8 +152,7 @@ class Fournisseur extends Societe
dol_syslog("Fournisseur::CreateCategory", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
dol_syslog("Fournisseur::CreateCategory : Success");
return 0;
} else {
@ -185,17 +178,19 @@ class Fournisseur extends Societe
$sql = "SELECT s.rowid, s.nom as name";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$user->socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.fournisseur = 1";
$sql .= " AND s.entity IN (".getEntity('societe').")";
if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if (!$user->rights->societe->client->voir && !$user->socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
$resql = $this->db->query($sql);
if ($resql)
{
while ($obj = $this->db->fetch_object($resql))
{
if ($resql) {
while ($obj = $this->db->fetch_object($resql)) {
$arr[$obj->rowid] = $obj->name;
}
} else {

File diff suppressed because it is too large Load Diff

View File

@ -140,16 +140,36 @@ class CommandeFournisseurDispatch extends CommonObject
// Clean parameters
if (isset($this->fk_commande)) $this->fk_commande = trim($this->fk_commande);
if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product);
if (isset($this->fk_commandefourndet)) $this->fk_commandefourndet = trim($this->fk_commandefourndet);
if (isset($this->qty)) $this->qty = trim($this->qty);
if (isset($this->fk_entrepot)) $this->fk_entrepot = trim($this->fk_entrepot);
if (isset($this->fk_user)) $this->fk_user = trim($this->fk_user);
if (isset($this->comment)) $this->comment = trim($this->comment);
if (isset($this->status)) $this->status = trim($this->status);
if (isset($this->batch)) $this->batch = trim($this->batch);
if (empty($this->datec)) $this->datec = dol_now();
if (isset($this->fk_commande)) {
$this->fk_commande = trim($this->fk_commande);
}
if (isset($this->fk_product)) {
$this->fk_product = trim($this->fk_product);
}
if (isset($this->fk_commandefourndet)) {
$this->fk_commandefourndet = trim($this->fk_commandefourndet);
}
if (isset($this->qty)) {
$this->qty = trim($this->qty);
}
if (isset($this->fk_entrepot)) {
$this->fk_entrepot = trim($this->fk_entrepot);
}
if (isset($this->fk_user)) {
$this->fk_user = trim($this->fk_user);
}
if (isset($this->comment)) {
$this->comment = trim($this->comment);
}
if (isset($this->status)) {
$this->status = trim($this->status);
}
if (isset($this->batch)) {
$this->batch = trim($this->batch);
}
if (empty($this->datec)) {
$this->datec = dol_now();
}
// Check parameters
@ -190,16 +210,16 @@ class CommandeFournisseurDispatch extends CommonObject
$this->db->begin();
dol_syslog(__METHOD__, LOG_DEBUG);
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
if (!$error)
{
if (!$error) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
if (!$notrigger)
{
if (!$notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
@ -211,17 +231,16 @@ class CommandeFournisseurDispatch extends CommonObject
}
// Create extrafields
if (!$error)
{
if (!$error) {
$result = $this->insertExtraFields();
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -264,15 +283,16 @@ class CommandeFournisseurDispatch extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
if ($ref) $sql .= " WHERE t.ref = '".$ref."'";
else $sql .= " WHERE t.rowid = ".$id;
if ($ref) {
$sql .= " WHERE t.ref = '".$ref."'";
} else {
$sql .= " WHERE t.rowid = ".$id;
}
dol_syslog(get_class($this)."::fetch");
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -318,15 +338,33 @@ class CommandeFournisseurDispatch extends CommonObject
// Clean parameters
if (isset($this->fk_commande)) $this->fk_commande = trim($this->fk_commande);
if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product);
if (isset($this->fk_commandefourndet)) $this->fk_commandefourndet = trim($this->fk_commandefourndet);
if (isset($this->qty)) $this->qty = trim($this->qty);
if (isset($this->fk_entrepot)) $this->fk_entrepot = trim($this->fk_entrepot);
if (isset($this->fk_user)) $this->fk_user = trim($this->fk_user);
if (isset($this->comment)) $this->comment = trim($this->comment);
if (isset($this->status)) $this->status = trim($this->status);
if (isset($this->batch)) $this->batch = trim($this->batch);
if (isset($this->fk_commande)) {
$this->fk_commande = trim($this->fk_commande);
}
if (isset($this->fk_product)) {
$this->fk_product = trim($this->fk_product);
}
if (isset($this->fk_commandefourndet)) {
$this->fk_commandefourndet = trim($this->fk_commandefourndet);
}
if (isset($this->qty)) {
$this->qty = trim($this->qty);
}
if (isset($this->fk_entrepot)) {
$this->fk_entrepot = trim($this->fk_entrepot);
}
if (isset($this->fk_user)) {
$this->fk_user = trim($this->fk_user);
}
if (isset($this->comment)) {
$this->comment = trim($this->comment);
}
if (isset($this->status)) {
$this->status = trim($this->status);
}
if (isset($this->batch)) {
$this->batch = trim($this->batch);
}
@ -357,34 +395,34 @@ class CommandeFournisseurDispatch extends CommonObject
dol_syslog(__METHOD__);
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
if (!$error)
{
if (!$error)
{
if (empty($this->id) && !empty($this->rowid))$this->id = $this->rowid;
if (!$error) {
if (!$error) {
if (empty($this->id) && !empty($this->rowid)) {
$this->id = $this->rowid;
}
$result = $this->insertExtraFields();
if ($result < 0)
{
if ($result < 0) {
$error++;
}
}
if (!$notrigger)
{
if (!$notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
$result = $this->call_trigger('LINERECEPTION_UPDATE', $user);
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
//// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -397,13 +435,13 @@ class CommandeFournisseurDispatch extends CommonObject
}
/**
* Delete object in database
*
* @param User $user User that deletes
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
/**
* Delete object in database
*
* @param User $user User that deletes
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
public function delete($user, $notrigger = 0)
{
global $conf, $langs;
@ -411,10 +449,8 @@ class CommandeFournisseurDispatch extends CommonObject
$this->db->begin();
if (!$error)
{
if (!$notrigger)
{
if (!$error) {
if (!$notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
@ -428,28 +464,26 @@ class CommandeFournisseurDispatch extends CommonObject
// Remove extrafields
if (!$error) {
$result = $this->deleteExtraFields();
if ($result < 0)
{
if ($result < 0) {
$error++;
dol_syslog(get_class($this)."::delete error deleteExtraFields ".$this->error, LOG_ERR);
}
}
if (!$error)
{
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " WHERE rowid=".$this->id;
dol_syslog(__METHOD__);
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -491,21 +525,18 @@ class CommandeFournisseurDispatch extends CommonObject
$result = $object->create($user);
// Other options
if ($result < 0)
{
if ($result < 0) {
$this->error = $object->error;
$error++;
}
if (!$error)
{
if (!$error) {
}
unset($object->context['createfromclone']);
// End
if (!$error)
{
if (!$error) {
$this->db->commit();
return $object->id;
} else {
@ -541,30 +572,36 @@ class CommandeFournisseurDispatch extends CommonObject
global $langs;
$langs->load('orders');
if ($mode == 0)
{
if ($mode == 0) {
return $langs->trans($this->statuts[$status]);
} elseif ($mode == 1)
{
} elseif ($mode == 1) {
return $langs->trans($this->statutshort[$status]);
} elseif ($mode == 2)
{
} elseif ($mode == 2) {
return $langs->trans($this->statuts[$status]);
} elseif ($mode == 3)
{
if ($status == 0) return img_picto($langs->trans($this->statuts[$status]), 'statut0');
elseif ($status == 1) return img_picto($langs->trans($this->statuts[$status]), 'statut4');
elseif ($status == 2) return img_picto($langs->trans($this->statuts[$status]), 'statut8');
} elseif ($mode == 4)
{
if ($status == 0) return img_picto($langs->trans($this->statuts[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]);
elseif ($status == 1) return img_picto($langs->trans($this->statuts[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]);
elseif ($status == 2) return img_picto($langs->trans($this->statuts[$status]), 'statut8').' '.$langs->trans($this->statuts[$status]);
} elseif ($mode == 5)
{
if ($status == 0) return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$status]).' </span>'.img_picto($langs->trans($this->statuts[$status]), 'statut0');
elseif ($status == 1) return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$status]).' </span>'.img_picto($langs->trans($this->statuts[$status]), 'statut4');
elseif ($status == 2) return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$status]).' </span>'.img_picto($langs->trans($this->statuts[$status]), 'statut8');
} elseif ($mode == 3) {
if ($status == 0) {
return img_picto($langs->trans($this->statuts[$status]), 'statut0');
} elseif ($status == 1) {
return img_picto($langs->trans($this->statuts[$status]), 'statut4');
} elseif ($status == 2) {
return img_picto($langs->trans($this->statuts[$status]), 'statut8');
}
} elseif ($mode == 4) {
if ($status == 0) {
return img_picto($langs->trans($this->statuts[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]);
} elseif ($status == 1) {
return img_picto($langs->trans($this->statuts[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]);
} elseif ($status == 2) {
return img_picto($langs->trans($this->statuts[$status]), 'statut8').' '.$langs->trans($this->statuts[$status]);
}
} elseif ($mode == 5) {
if ($status == 0) {
return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$status]).' </span>'.img_picto($langs->trans($this->statuts[$status]), 'statut0');
} elseif ($status == 1) {
return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$status]).' </span>'.img_picto($langs->trans($this->statuts[$status]), 'statut4');
} elseif ($status == 2) {
return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$status]).' </span>'.img_picto($langs->trans($this->statuts[$status]), 'statut8');
}
}
}
@ -610,7 +647,7 @@ class CommandeFournisseurDispatch extends CommonObject
{
dol_syslog(__METHOD__, LOG_DEBUG);
$sql = "SELECT";
$sql = "SELECT";
$sql .= " t.rowid,";
$sql .= " t.fk_commande,";

File diff suppressed because it is too large Load Diff

View File

@ -168,14 +168,12 @@ class ProductFournisseur extends Product
dol_syslog(get_class($this)."::remove_fournisseur", LOG_DEBUG);
$resql2 = $this->db->query($sql);
if (!$resql2)
{
if (!$resql2) {
$this->error = $this->db->lasterror();
$ok = 0;
}
if ($ok)
{
if ($ok) {
$this->db->commit();
return 1;
} else {
@ -203,18 +201,18 @@ class ProductFournisseur extends Product
// Call trigger
$result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_DELETE', $user);
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
// End call triggers
if (empty($error))
{
if (empty($error)) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
$sql .= " WHERE rowid = ".$rowid;
dol_syslog(get_class($this)."::remove_product_fournisseur_price", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$this->error = $this->db->lasterror();
$error++;
}
@ -266,15 +264,28 @@ class ProductFournisseur extends Product
//global $mysoc;
// Clean parameter
if (empty($qty)) $qty = 0;
if (empty($buyprice)) $buyprice = 0;
if (empty($charges)) $charges = 0;
if (empty($availability)) $availability = 0;
if (empty($remise_percent)) $remise_percent = 0;
if (empty($supplier_reputation) || $supplier_reputation == -1) $supplier_reputation = '';
if ($delivery_time_days != '' && !is_numeric($delivery_time_days)) $delivery_time_days = '';
if ($price_base_type == 'TTC')
{
if (empty($qty)) {
$qty = 0;
}
if (empty($buyprice)) {
$buyprice = 0;
}
if (empty($charges)) {
$charges = 0;
}
if (empty($availability)) {
$availability = 0;
}
if (empty($remise_percent)) {
$remise_percent = 0;
}
if (empty($supplier_reputation) || $supplier_reputation == -1) {
$supplier_reputation = '';
}
if ($delivery_time_days != '' && !is_numeric($delivery_time_days)) {
$delivery_time_days = '';
}
if ($price_base_type == 'TTC') {
$ttx = $tva_tx;
$buyprice = $buyprice / (1 + ($ttx / 100));
}
@ -283,10 +294,13 @@ class ProductFournisseur extends Product
$multicurrency_unitBuyPrice = null;
$fk_multicurrency = null;
if (!empty($conf->multicurrency->enabled)) {
if (empty($multicurrency_tx)) $multicurrency_tx = 1;
if (empty($multicurrency_buyprice)) $multicurrency_buyprice = 0;
if ($multicurrency_price_base_type == 'TTC')
{
if (empty($multicurrency_tx)) {
$multicurrency_tx = 1;
}
if (empty($multicurrency_buyprice)) {
$multicurrency_buyprice = 0;
}
if ($multicurrency_price_base_type == 'TTC') {
$ttx = $tva_tx;
$multicurrency_buyprice = $multicurrency_buyprice / (1 + ($ttx / 100));
}
@ -309,8 +323,7 @@ class ProductFournisseur extends Product
$newvat = $tva_tx;
if (count($localtaxes_array) > 0)
{
if (count($localtaxes_array) > 0) {
$localtaxtype1 = $localtaxes_array['0'];
$localtax1 = $localtaxes_array['1'];
$localtaxtype2 = $localtaxes_array['2'];
@ -321,26 +334,26 @@ class ProductFournisseur extends Product
$localtaxtype2 = '0';
$localtax2 = get_localtax($newvat, 2);
}
if (empty($localtax1)) $localtax1 = 0; // If = '' then = 0
if (empty($localtax2)) $localtax2 = 0; // If = '' then = 0
if (empty($localtax1)) {
$localtax1 = 0; // If = '' then = 0
}
if (empty($localtax2)) {
$localtax2 = 0; // If = '' then = 0
}
// Check parameters
if ($buyprice != '' && !is_numeric($buyprice))
{
if ($buyprice != '' && !is_numeric($buyprice)) {
}
$this->db->begin();
if ($this->product_fourn_price_id > 0)
{
if ($this->product_fourn_price_id > 0) {
// check if price already logged, if not first log current price
$logPrices = $this->listProductFournisseurPriceLog($this->product_fourn_price_id);
if (is_array($logPrices) && count($logPrices) == 0)
{
if (is_array($logPrices) && count($logPrices) == 0) {
$currentPfp = new self($this->db);
$result = $currentPfp->fetch_product_fournisseur_price($this->product_fourn_price_id);
if ($result > 0 && $currentPfp->fourn_price != 0)
{
if ($result > 0 && $currentPfp->fourn_price != 0) {
$currentPfpUser = new User($this->db);
$result = $currentPfpUser->fetch($currentPfp->user_id);
if ($result > 0) {
@ -387,27 +400,28 @@ class ProductFournisseur extends Product
$sql .= " supplier_reputation = ".(empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'").",";
$sql .= " barcode = ".(empty($barcode) ? 'NULL' : "'".$this->db->escape($barcode)."'").",";
$sql .= " fk_barcode_type = ".(empty($fk_barcode_type) ? 'NULL' : "'".$this->db->escape($fk_barcode_type)."'");
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .= ", packaging = ".(empty($packaging) ? 1 : $packaging);
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$sql .= ", packaging = ".(empty($packaging) ? 1 : $packaging);
}
$sql .= " WHERE rowid = ".$this->product_fourn_price_id;
// TODO Add price_base_type and price_ttc
dol_syslog(get_class($this).'::update_buyprice update knowing id of line = product_fourn_price_id = '.$this->product_fourn_price_id, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
// Call trigger
$result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_UPDATE', $user);
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
// End call triggers
if (!$error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG))
{
if (!$error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG)) {
$result = $this->logPrice($user, $now, $buyprice, $qty, $multicurrency_buyprice, $multicurrency_unitBuyPrice, $multicurrency_tx, $fk_multicurrency, $multicurrency_code);
if ($result < 0) {
$error++;
}
}
if (empty($error))
{
if (empty($error)) {
$this->db->commit();
return $this->product_fourn_price_id;
} else {
@ -431,7 +445,9 @@ class ProductFournisseur extends Product
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
$sql .= " multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,";
$sql .= "datec, fk_product, fk_soc, ref_fourn, desc_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, fk_availability, default_vat_code, info_bits, entity, delivery_time_days, supplier_reputation, barcode, fk_barcode_type)";
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .= ", packaging";
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$sql .= ", packaging";
}
$sql .= " values(";
$sql .= (isset($multicurrency_buyprice) ? "'".$this->db->escape(price2num($multicurrency_buyprice))."'" : 'null').",";
$sql .= (isset($multicurrency_unitBuyPrice) ? "'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'" : 'null').",";
@ -459,7 +475,9 @@ class ProductFournisseur extends Product
$sql .= (empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'").",";
$sql .= (empty($barcode) ? 'NULL' : "'".$this->db->escape($barcode)."'").",";
$sql .= (empty($fk_barcode_type) ? 'NULL' : "'".$this->db->escape($fk_barcode_type)."'");
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .= ", ".(empty($this->packaging) ? 1 : $this->db->escape($this->packaging));
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$sql .= ", ".(empty($this->packaging) ? 1 : $this->db->escape($this->packaging));
}
$sql .= ")";
$this->product_fourn_price_id = 0;
@ -483,8 +501,9 @@ class ProductFournisseur extends Product
if (!$error) {
// Call trigger
$result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_CREATE', $user);
if ($result < 0)
if ($result < 0) {
$error++;
}
// End call triggers
if (empty($error)) {
@ -532,11 +551,9 @@ class ProductFournisseur extends Product
dol_syslog(get_class($this)."::fetch_product_fournisseur_price", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj)
{
if ($obj) {
$this->product_fourn_price_id = $rowid;
$this->id = $obj->fk_product;
@ -578,18 +595,18 @@ class ProductFournisseur extends Product
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$this->packaging = $obj->packaging;
if ($this->packaging < $this->fourn_qty) $this->packaging = $this->fourn_qty;
if ($this->packaging < $this->fourn_qty) {
$this->packaging = $this->fourn_qty;
}
}
if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression))
{
if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) {
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProductSupplier($this);
if ($price_result >= 0) {
$this->fourn_price = $price_result;
//recalculation of unitprice, as probably the price changed...
if ($this->fourn_qty != 0)
{
if ($this->fourn_qty != 0) {
$this->fourn_unitprice = price2num($this->fourn_price / $this->fourn_qty, 'MU');
} else {
$this->fourn_unitprice = "";
@ -629,24 +646,27 @@ class ProductFournisseur extends Product
$sql .= " pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability, pfp.charges, pfp.info_bits, pfp.delivery_time_days, pfp.supplier_reputation,";
$sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code, pfp.datec, pfp.tms,";
$sql .= " pfp.barcode, pfp.fk_barcode_type";
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .= ", pfp.packaging";
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$sql .= ", pfp.packaging";
}
$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")";
$sql .= " AND pfp.fk_soc = s.rowid AND pfp.fk_product = p.rowid";
$sql .= " AND s.status=1"; // only enabled company selected
$sql .= " AND pfp.fk_product = ".$prodid;
if (empty($sortfield)) $sql .= " ORDER BY s.nom, pfp.quantity, pfp.price";
else $sql .= $this->db->order($sortfield, $sortorder);
if (empty($sortfield)) {
$sql .= " ORDER BY s.nom, pfp.quantity, pfp.price";
} else {
$sql .= $this->db->order($sortfield, $sortorder);
}
$sql .= $this->db->plimit($limit, $offset);
dol_syslog(get_class($this)."::list_product_fournisseur_price", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$retarray = array();
while ($record = $this->db->fetch_array($resql))
{
while ($record = $this->db->fetch_array($resql)) {
//define base attribute
$prodfourn = new ProductFournisseur($this->db);
@ -683,7 +703,9 @@ class ProductFournisseur extends Product
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$prodfourn->packaging = $record["packaging"];
if ($prodfourn->packaging < $prodfourn->fourn_qty) $prodfourn->packaging = $prodfourn->fourn_qty;
if ($prodfourn->packaging < $prodfourn->fourn_qty) {
$prodfourn->packaging = $prodfourn->fourn_qty;
}
}
if (!empty($conf->barcode->enabled)) {
@ -700,10 +722,8 @@ class ProductFournisseur extends Product
}
}
if (!isset($prodfourn->fourn_unitprice))
{
if ($prodfourn->fourn_qty != 0)
{
if (!isset($prodfourn->fourn_unitprice)) {
if ($prodfourn->fourn_qty != 0) {
$prodfourn->fourn_unitprice = price2num($prodfourn->fourn_price / $prodfourn->fourn_qty, 'MU');
} else {
$prodfourn->fourn_unitprice = "";
@ -735,8 +755,7 @@ class ProductFournisseur extends Product
// phpcs:enable
global $conf;
if (empty($prodid))
{
if (empty($prodid)) {
dol_syslog("Warning function find_min_price_product_fournisseur were called with prodid empty. May be a bug.", LOG_WARNING);
return 0;
}
@ -771,30 +790,30 @@ class ProductFournisseur extends Product
$sql .= " AND pfp.fk_product = ".$prodid;
$sql .= " AND pfp.fk_soc = s.rowid";
$sql .= " AND s.status = 1"; // only enabled society
if ($qty > 0) $sql .= " AND pfp.quantity <= ".$qty;
if ($socid > 0) $sql .= ' AND pfp.fk_soc = '.$socid;
if ($qty > 0) {
$sql .= " AND pfp.quantity <= ".$qty;
}
if ($socid > 0) {
$sql .= ' AND pfp.fk_soc = '.$socid;
}
dol_syslog(get_class($this)."::find_min_price_product_fournisseur", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$record_array = array();
//Store each record to array for later search of min
while ($record = $this->db->fetch_array($resql))
{
while ($record = $this->db->fetch_array($resql)) {
$record_array[] = $record;
}
if (count($record_array) == 0)
{
if (count($record_array) == 0) {
$this->db->free($resql);
return 0;
} else {
$min = -1;
foreach ($record_array as $record)
{
foreach ($record_array as $record) {
$fourn_price = $record["price"];
// discount calculated buy price
$fourn_unitprice = $record["unitprice"] * (1 - $record["remise_percent"] / 100) - $record["remise"];
@ -809,16 +828,14 @@ class ProductFournisseur extends Product
$price_result = $priceparser->parseProductSupplier($prod_supplier);
if ($price_result >= 0) {
$fourn_price = price2num($price_result, 'MU');
if ($record["quantity"] != 0)
{
if ($record["quantity"] != 0) {
$fourn_unitprice = price2num($fourn_price / $record["quantity"], 'MU');
} else {
$fourn_unitprice = $fourn_price;
}
}
}
if ($fourn_unitprice < $min || $min == -1)
{
if ($fourn_unitprice < $min || $min == -1) {
$this->product_fourn_price_id = $record["product_fourn_price_id"];
$this->ref_supplier = $record["ref_fourn"];
$this->ref_fourn = $record["ref_fourn"]; // deprecated
@ -874,8 +891,7 @@ class ProductFournisseur extends Product
dol_syslog(get_class($this)."::setSupplierPriceExpression", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$this->db->commit();
return 1;
} else {
@ -982,18 +998,19 @@ class ProductFournisseur extends Product
$sql .= " AND pfpl.fk_user = u.rowid";
$sql .= " AND pfp.rowid = pfpl.fk_product_fournisseur";
$sql .= " AND pfpl.fk_product_fournisseur = ".$product_fourn_price_id;
if (empty($sortfield)) $sql .= " ORDER BY pfpl.datec";
else $sql .= $this->db->order($sortfield, $sortorder);
if (empty($sortfield)) {
$sql .= " ORDER BY pfpl.datec";
} else {
$sql .= $this->db->order($sortfield, $sortorder);
}
$sql .= $this->db->plimit($limit, $offset);
dol_syslog(get_class($this)."::list_product_fournisseur_price_log", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$retarray = array();
while ($obj = $this->db->fetch_object($resql))
{
while ($obj = $this->db->fetch_object($resql)) {
$tmparray = array();
$tmparray['rowid'] = $obj->rowid;
$tmparray['supplier_ref'] = $obj->supplier_ref;
@ -1126,7 +1143,9 @@ class ProductFournisseur extends Product
if ($this->height) {
$labelsize .= ($labelsize ? " - " : "")."<b>".$langs->trans("Height").'</b>: '.$this->height.' '.measuringUnitString(0, 'size', $this->height_units);
}
if ($labelsize) $label .= "<br>".$labelsize;
if ($labelsize) {
$label .= "<br>".$labelsize;
}
$labelsurfacevolume = "";
if ($this->surface) {
@ -1135,7 +1154,9 @@ class ProductFournisseur extends Product
if ($this->volume) {
$labelsurfacevolume .= ($labelsurfacevolume ? " - " : "")."<b>".$langs->trans("Volume").'</b>: '.$this->volume.' '.measuringUnitString(0, 'volume', $this->volume_units);
}
if ($labelsurfacevolume) $label .= "<br>".$labelsurfacevolume;
if ($labelsurfacevolume) {
$label .= "<br>".$labelsurfacevolume;
}
}
if (!empty($conf->accounting->enabled) && $this->status) {

View File

@ -98,20 +98,19 @@ class PaiementFourn extends Paiement
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
$sql .= ' WHERE p.entity IN ('.getEntity('facture_fourn').')';
if ($id > 0)
if ($id > 0) {
$sql .= ' AND p.rowid = '.$id;
elseif ($ref)
} elseif ($ref) {
$sql .= ' AND p.rowid = '.$ref;
elseif ($fk_bank)
} elseif ($fk_bank) {
$sql .= ' AND p.fk_bank = '.$fk_bank;
}
//print $sql;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
if ($num > 0)
{
if ($num > 0) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -166,8 +165,7 @@ class PaiementFourn extends Paiement
dol_syslog(get_class($this)."::create", LOG_DEBUG);
if ($way == 'dolibarr')
{
if ($way == 'dolibarr') {
$amounts = &$this->amounts;
$amounts_to_update = &$this->multicurrency_amounts;
} else {
@ -175,8 +173,7 @@ class PaiementFourn extends Paiement
$amounts_to_update = &$this->amounts;
}
foreach ($amounts as $key => $value)
{
foreach ($amounts as $key => $value) {
$value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value ? $value : 0, $way, 'facture_fourn');
$totalamount_converted += $value_converted;
$amounts_to_update[$key] = price2num($value_converted, 'MT');
@ -190,13 +187,11 @@ class PaiementFourn extends Paiement
$this->db->begin();
if ($totalamount <> 0) // On accepte les montants negatifs
{
if ($totalamount <> 0) { // On accepte les montants negatifs
$ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
$now = dol_now();
if ($way == 'dolibarr')
{
if ($way == 'dolibarr') {
$total = $totalamount;
$mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
} else {
@ -210,28 +205,23 @@ class PaiementFourn extends Paiement
$sql .= " '".$this->db->idate($this->datepaye)."', '".$total."', '".$mtotal."', ".$this->paiementid.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_private)."', ".$user->id.", 0)";
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiementfourn');
// Insere tableau des montants / factures
foreach ($this->amounts as $key => $amount)
{
foreach ($this->amounts as $key => $amount) {
$facid = $key;
if (is_numeric($amount) && $amount <> 0)
{
if (is_numeric($amount) && $amount <> 0) {
$amount = price2num($amount);
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount)';
$sql .= ' VALUES ('.$facid.','.$this->id.',\''.$amount.'\', \''.$this->multicurrency_amounts[$key].'\')';
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$invoice = new FactureFournisseur($this->db);
$invoice->fetch($facid);
// If we want to closed paid invoices
if ($closepaidinvoices)
{
if ($closepaidinvoices) {
$paiement = $invoice->getSommePaiement();
//$creditnotes=$invoice->getSumCreditNotesUsed();
$creditnotes = 0;
@ -239,18 +229,20 @@ class PaiementFourn extends Paiement
$deposits = 0;
$alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
$remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
if ($remaintopay == 0)
{
if ($remaintopay == 0) {
$result = $invoice->setPaid($user, '', '');
} else dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing.");
} else {
dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing.");
}
}
// Regenerate documents of invoices
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
$newlang = '';
$outputlangs = $langs;
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang;
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
$newlang = $invoice->thirdparty->default_lang;
}
if (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
@ -271,11 +263,12 @@ class PaiementFourn extends Paiement
}
}
if (!$error)
{
if (!$error) {
// Call trigger
$result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user);
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
// End call triggers
}
} else {
@ -288,8 +281,7 @@ class PaiementFourn extends Paiement
$error++;
}
if ($totalamount <> 0 && $error == 0) // On accepte les montants negatifs
{
if ($totalamount <> 0 && $error == 0) { // On accepte les montants negatifs
$this->amount = $total;
$this->total = $total;
$this->multicurrency_amount = $mtotal;
@ -322,10 +314,8 @@ class PaiementFourn extends Paiement
// Verifier si paiement porte pas sur une facture a l'etat payee
// Si c'est le cas, on refuse la suppression
$billsarray = $this->getBillsArray('paye=1');
if (is_array($billsarray))
{
if (count($billsarray))
{
if (is_array($billsarray)) {
if (count($billsarray)) {
$this->error = "ErrorCantDeletePaymentSharedWithPayedInvoice";
$this->db->rollback();
return -1;
@ -337,12 +327,10 @@ class PaiementFourn extends Paiement
// Verifier si paiement ne porte pas sur ecriture bancaire rapprochee
// Si c'est le cas, on refuse le delete
if ($bank_line_id)
{
if ($bank_line_id) {
$accline = new AccountLine($this->db);
$accline->fetch($bank_line_id);
if ($accline->rappro)
{
if ($accline->rappro) {
$this->error = "ErrorCantDeletePaymentReconciliated";
$this->db->rollback();
return -3;
@ -353,41 +341,34 @@ class PaiementFourn extends Paiement
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
$sql .= ' WHERE fk_paiementfourn = '.$this->id;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn';
$sql .= ' WHERE rowid = '.$this->id;
$result = $this->db->query($sql);
if (!$result)
{
if (!$result) {
$this->error = $this->db->error();
$this->db->rollback();
return -3;
}
// Supprimer l'ecriture bancaire si paiement lie a ecriture
if ($bank_line_id)
{
if ($bank_line_id) {
$accline = new AccountLine($this->db);
$result = $accline->fetch($bank_line_id);
if ($result > 0) // If result = 0, record not found, we don't try to delete
{
if ($result > 0) { // If result = 0, record not found, we don't try to delete
$result = $accline->delete($user);
}
if ($result < 0)
{
if ($result < 0) {
$this->error = $accline->error;
$this->db->rollback();
return -4;
}
}
if (!$notrigger)
{
if (!$notrigger) {
// Appel des triggers
$result = $this->call_trigger('PAYMENT_SUPPLIER_DELETE', $user);
if ($result < 0)
{
if ($result < 0) {
$this->db->rollback();
return -1;
}
@ -416,22 +397,18 @@ class PaiementFourn extends Paiement
$sql .= ' WHERE c.rowid = '.$id;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
if ($num)
{
if ($num) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
if ($obj->fk_user_creat)
{
if ($obj->fk_user_creat) {
$cuser = new User($this->db);
$cuser->fetch($obj->fk_user_creat);
$this->user_creation = $cuser;
}
if ($obj->fk_user_modif)
{
if ($obj->fk_user_modif) {
$muser = new User($this->db);
$muser->fetch($obj->fk_user_modif);
$this->user_modification = $muser;
@ -456,18 +433,18 @@ class PaiementFourn extends Paiement
$sql = 'SELECT fk_facturefourn';
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'facture_fourn as f';
$sql .= ' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.$this->id;
if ($filter) $sql .= ' AND '.$filter;
if ($filter) {
$sql .= ' AND '.$filter;
}
dol_syslog(get_class($this).'::getBillsArray', LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$i = 0;
$num = $this->db->num_rows($resql);
$billsarray = array();
while ($i < $num)
{
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$billsarray[$i] = $obj->fk_facturefourn;
$i++;
@ -564,20 +541,28 @@ class PaiementFourn extends Paiement
$reg = array();
if (preg_match('/^\((.*)\)$/i', $text, $reg)) {
// Label generique car entre parentheses. On l'affiche en le traduisant
if ($reg[1] == 'paiement') $reg[1] = 'Payment';
if ($reg[1] == 'paiement') {
$reg[1] = 'Payment';
}
$text = $langs->trans($reg[1]);
}
$label = '<u>'.$langs->trans("Payment").'</u><br>';
$label .= '<strong>'.$langs->trans("Ref").':</strong> '.$text;
if ($this->datepaye ? $this->datepaye : $this->date) $label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($this->datepaye ? $this->datepaye : $this->date, 'dayhour');
if ($this->datepaye ? $this->datepaye : $this->date) {
$label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($this->datepaye ? $this->datepaye : $this->date, 'dayhour');
}
$linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result .= $this->ref;
if ($withpicto) {
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
}
if ($withpicto != 2) {
$result .= $this->ref;
}
$result .= $linkend;
return $result;
@ -622,12 +607,15 @@ class PaiementFourn extends Paiement
$langs->load("bills");
// Clean parameters (if not defined or using deprecated value)
if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
elseif ($conf->global->SUPPLIER_PAYMENT_ADDON == 'brodator') $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_brodator';
elseif ($conf->global->SUPPLIER_PAYMENT_ADDON == 'bronan') $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) {
$conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
} elseif ($conf->global->SUPPLIER_PAYMENT_ADDON == 'brodator') {
$conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_brodator';
} elseif ($conf->global->SUPPLIER_PAYMENT_ADDON == 'bronan') {
$conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
}
if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON))
{
if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON)) {
$mybool = false;
$file = $conf->global->SUPPLIER_PAYMENT_ADDON.".php";
@ -640,8 +628,7 @@ class PaiementFourn extends Paiement
$dir = dol_buildpath($reldir."core/modules/supplier_payment/");
// Load file with numbering class (if found)
if (is_file($dir.$file) && is_readable($dir.$file))
{
if (is_file($dir.$file) && is_readable($dir.$file)) {
$mybool |= include_once $dir.$file;
}
}
@ -706,18 +693,15 @@ class PaiementFourn extends Paiement
$langs->load("suppliers");
// Set the model on the model name to use
if (empty($modele))
{
if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF))
{
if (empty($modele)) {
if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF)) {
$modele = $conf->global->SUPPLIER_PAYMENT_ADDON_PDF;
} else {
$modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation
}
}
if (empty($modele))
{
if (empty($modele)) {
return 0;
} else {
$modelpath = "core/modules/supplier_payment/doc/";
@ -738,12 +722,9 @@ class PaiementFourn extends Paiement
global $conf;
$way = 'dolibarr';
if (!empty($conf->multicurrency->enabled))
{
foreach ($this->multicurrency_amounts as $value)
{
if (!empty($value)) // one value found then payment is in invoice currency
{
if (!empty($conf->multicurrency->enabled)) {
foreach ($this->multicurrency_amounts as $value) {
if (!empty($value)) { // one value found then payment is in invoice currency
$way = 'customer';
break;
}
@ -766,14 +747,11 @@ class PaiementFourn extends Paiement
// phpcs:enable
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
if (empty($force_thirdparty_id))
{
if (empty($force_thirdparty_id)) {
$billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
if (!empty($billsarray))
{
if (!empty($billsarray)) {
$supplier_invoice = new FactureFournisseur($this->db);
if ($supplier_invoice->fetch($billsarray[0]) > 0)
{
if ($supplier_invoice->fetch($billsarray[0]) > 0) {
$force_thirdparty_id = $supplier_invoice->fk_soc;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,9 @@ $ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande');
$object = new CommandeFournisseur($db);
@ -51,51 +53,39 @@ $object = new CommandeFournisseur($db);
* Add a new contact
*/
if ($action == 'addcontact' && $user->rights->fournisseur->commande->creer)
{
if ($action == 'addcontact' && $user->rights->fournisseur->commande->creer) {
$result = $object->fetch($id);
if ($result > 0 && $id > 0)
{
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)
{
if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
} else {
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
$langs->load("errors");
setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
}
// Toggle the status of a contact
elseif ($action == 'swapstatut' && $user->rights->fournisseur->commande->creer)
{
if ($object->fetch($id))
{
} elseif ($action == 'swapstatut' && $user->rights->fournisseur->commande->creer) {
// Toggle the status of a contact
if ($object->fetch($id)) {
$result = $object->swapContactStatus(GETPOST('ligne'));
} else {
dol_print_error($db);
}
}
// Deleting a contact
elseif ($action == 'deletecontact' && $user->rights->fournisseur->commande->creer)
{
} elseif ($action == 'deletecontact' && $user->rights->fournisseur->commande->creer) {
// Deleting a contact
$object->fetch($id);
$result = $object->delete_contact($_GET["lineid"]);
if ($result >= 0)
{
if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
} else {
@ -123,12 +113,10 @@ $userstatic = new User($db);
/* */
/* *************************************************************************** */
if ($id > 0 || !empty($ref))
{
if ($id > 0 || !empty($ref)) {
$langs->trans("OrderCard");
if ($object->fetch($id, $ref) > 0)
{
if ($object->fetch($id, $ref) > 0) {
$object->fetch_thirdparty();
$head = ordersupplier_prepare_head($object);
@ -145,12 +133,10 @@ if ($id > 0 || !empty($ref))
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->fournisseur->commande->creer)
{
if ($user->rights->fournisseur->commande->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref .= ' : ';

View File

@ -40,14 +40,16 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
if (!empty($conf->projet->enabled))
if (!empty($conf->projet->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
}
// Load translation files required by the page
$langs->loadLangs(array("bills", "orders", "sendings", "companies", "deliveries", "products", "stocks", "receptions"));
if (!empty($conf->productbatch->enabled))
if (!empty($conf->productbatch->enabled)) {
$langs->load('productbatch');
}
// Security check
$id = GETPOST("id", 'int');
@ -58,8 +60,9 @@ $fk_default_warehouse = GETPOST('fk_default_warehouse', 'int');
$cancel = GETPOST('cancel', 'alpha');
$confirm = GETPOST('confirm', 'alpha');
if ($user->socid)
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande');
if (empty($conf->stock->enabled)) {
@ -70,8 +73,9 @@ $hookmanager->initHooks(array('ordersupplierdispatch'));
// Recuperation de l'id de projet
$projectid = 0;
if ($_GET["projectid"])
if ($_GET["projectid"]) {
$projectid = GETPOST("projectid", 'int');
}
$object = new CommandeFournisseur($db);
@ -93,25 +97,24 @@ if ($id > 0 || !empty($ref)) {
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if ($action == 'checkdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))))
{
if ($action == 'checkdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) {
$error = 0;
$supplierorderdispatch = new CommandeFournisseurDispatch($db);
$db->begin();
$result = $supplierorderdispatch->fetch($lineid);
if (!$result)
{
if (!$result) {
$error++;
setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
$action = '';
}
if (!$error)
{
if (!$error) {
$result = $supplierorderdispatch->setStatut(1);
if ($result < 0) {
setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
@ -120,8 +123,7 @@ if ($action == 'checkdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_
}
}
if (!$error)
{
if (!$error) {
$result = $object->calcAndSetStatusDispatch($user);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
@ -129,31 +131,27 @@ if ($action == 'checkdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_
$action = '';
}
}
if (!$error)
{
if (!$error) {
$db->commit();
} else {
$db->rollback();
}
}
if ($action == 'uncheckdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))))
{
if ($action == 'uncheckdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) {
$error = 0;
$supplierorderdispatch = new CommandeFournisseurDispatch($db);
$db->begin();
$result = $supplierorderdispatch->fetch($lineid);
if (!$result)
{
if (!$result) {
$error++;
setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
$action = '';
}
if (!$error)
{
if (!$error) {
$result = $supplierorderdispatch->setStatut(0);
if ($result < 0) {
setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
@ -161,8 +159,7 @@ if ($action == 'uncheckdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCE
$action = '';
}
}
if (!$error)
{
if (!$error) {
$result = $object->calcAndSetStatusDispatch($user);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
@ -170,31 +167,27 @@ if ($action == 'uncheckdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCE
$action = '';
}
}
if (!$error)
{
if (!$error) {
$db->commit();
} else {
$db->rollback();
}
}
if ($action == 'denydispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))))
{
if ($action == 'denydispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) {
$error = 0;
$supplierorderdispatch = new CommandeFournisseurDispatch($db);
$db->begin();
$result = $supplierorderdispatch->fetch($lineid);
if (!$result)
{
if (!$result) {
$error++;
setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
$action = '';
}
if (!$error)
{
if (!$error) {
$result = $supplierorderdispatch->setStatut(2);
if ($result < 0) {
setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
@ -202,8 +195,7 @@ if ($action == 'denydispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_P
$action = '';
}
}
if (!$error)
{
if (!$error) {
$result = $object->calcAndSetStatusDispatch($user);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
@ -211,8 +203,7 @@ if ($action == 'denydispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_P
$action = '';
}
}
if (!$error)
{
if (!$error) {
$db->commit();
} else {
$db->rollback();
@ -225,12 +216,10 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
$db->begin();
$pos = 0;
foreach ($_POST as $key => $value)
{
foreach ($_POST as $key => $value) {
// without batch module enabled
$reg = array();
if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg))
{
if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
$pos++;
// $numline=$reg[2] + 1; // line of product
@ -238,7 +227,9 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
$prod = "product_".$reg[1].'_'.$reg[2];
$qty = "qty_".$reg[1].'_'.$reg[2];
$ent = "entrepot_".$reg[1].'_'.$reg[2];
if (empty(GETPOST($ent))) $ent = $fk_default_warehouse;
if (empty(GETPOST($ent))) {
$ent = $fk_default_warehouse;
}
$pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount
$fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2];
@ -293,8 +284,7 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
}
}
// with batch module enabled
if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg))
{
if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
$pos++;
// eat-by date dispatch
@ -398,14 +388,12 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
}
// Remove a dispatched line
if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fournisseur->commande->receptionner)
{
if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fournisseur->commande->receptionner) {
$db->begin();
$supplierorderdispatch = new CommandeFournisseurDispatch($db);
$result = $supplierorderdispatch->fetch($lineid);
if ($result > 0)
{
if ($result > 0) {
$qty = $supplierorderdispatch->qty;
$entrepot = $supplierorderdispatch->fk_entrepot;
$product = $supplierorderdispatch->fk_product;
@ -417,48 +405,39 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fourn
$result = $supplierorderdispatch->delete($user);
}
if ($result < 0)
{
if ($result < 0) {
$errors = $object->errors;
$error++;
}
else {
} else {
// If module stock is enabled and the stock increase is done on purchase order dispatching
if ($entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER))
{
if ($entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
$mouv = new MouvementStock($db);
if ($product > 0)
{
if ($product > 0) {
$mouv->origin = &$object;
$result = $mouv->livraison($user, $product, $entrepot, $qty, $price, $comment, '', $eatby, $sellby, $batch);
if ($result < 0)
{
if ($result < 0) {
$errors = $mouv->errors;
$error++;
}
}
}
}
if ($error > 0)
{
if ($error > 0) {
$db->rollback();
setEventMessages($error, $errors, 'errors');
}
else {
} else {
$db->commit();
}
}
// Update a dispatched line
if ($action == 'updateline' && $user->rights->fournisseur->commande->receptionner)
{
if ($action == 'updateline' && $user->rights->fournisseur->commande->receptionner) {
$db->begin();
$error = 0;
$supplierorderdispatch = new CommandeFournisseurDispatch($db);
$result = $supplierorderdispatch->fetch($lineid);
if ($result > 0)
{
if ($result > 0) {
$qty = $supplierorderdispatch->qty;
$entrepot = $supplierorderdispatch->fk_entrepot;
$product = $supplierorderdispatch->fk_product;
@ -472,30 +451,23 @@ if ($action == 'updateline' && $user->rights->fournisseur->commande->receptionne
$supplierorderdispatch->fk_entrepot = GETPOST('fk_entrepot');
$result = $supplierorderdispatch->update($user);
}
if ($result < 0)
{
if ($result < 0) {
$error++;
$errors = $supplierorderdispatch->errors;
}
else {
} else {
// If module stock is enabled and the stock increase is done on purchase order dispatching
if ($entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER))
{
if ($entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
$mouv = new MouvementStock($db);
if ($product > 0)
{
if ($product > 0) {
$mouv->origin = &$object;
$result = $mouv->livraison($user, $product, $entrepot, $qty, $price, $comment, '', $eatby, $sellby, $batch);
if ($result < 0)
{
if ($result < 0) {
$errors = $mouv->errors;
$error++;
}
else {
} else {
$mouv->origin = &$object;
$result = $mouv->reception($user, $product, $supplierorderdispatch->fk_entrepot, $supplierorderdispatch->qty, $price, $comment, $eatby, $sellby, $batch);
if ($result < 0)
{
if ($result < 0) {
$errors = $mouv->errors;
$error++;
}
@ -503,12 +475,10 @@ if ($action == 'updateline' && $user->rights->fournisseur->commande->receptionne
}
}
}
if ($error > 0)
{
if ($error > 0) {
$db->rollback();
setEventMessages($error, $errors, 'errors');
}
else {
} else {
$db->commit();
}
}
@ -544,8 +514,7 @@ if ($id > 0 || !empty($ref)) {
$formconfirm = '';
// Confirmation to delete line
if ($action == 'ask_deleteline')
{
if ($action == 'ask_deleteline') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
}
@ -553,8 +522,11 @@ if ($id > 0 || !empty($ref)) {
$parameters = array('lineid' => $lineid);
// Note that $action and $object may be modified by hook
$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action);
if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
if (empty($reshook)) {
$formconfirm .= $hookmanager->resPrint;
} elseif ($reshook > 0) {
$formconfirm = $hookmanager->resPrint;
}
// Print form confirm
print $formconfirm;
@ -570,12 +542,10 @@ if ($id > 0 || !empty($ref)) {
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->fournisseur->commande->creer)
{
if ($user->rights->fournisseur->commande->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref .= ' : ';
@ -643,8 +613,9 @@ if ($id > 0 || !empty($ref)) {
print '<br>';
$disabled = 1;
if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER))
if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
$disabled = 0;
}
// Line of orders
if ($object->statut <= CommandeFournisseur::STATUS_ACCEPTED || $object->statut >= CommandeFournisseur::STATUS_CANCELED) {
@ -653,8 +624,7 @@ if ($id > 0 || !empty($ref)) {
if ($object->statut == CommandeFournisseur::STATUS_ORDERSENT
|| $object->statut == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY
|| $object->statut == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY)
{
|| $object->statut == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) {
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
$formproduct = new FormProduct($db);
$formproduct->loadWarehouses();
@ -662,12 +632,18 @@ if ($id > 0 || !empty($ref)) {
$listwarehouses = $entrepot->list_array(1);
if (empty($conf->reception->enabled))print '<form method="POST" action="dispatch.php?id='.$object->id.'">';
else print '<form method="post" action="'.dol_buildpath('/reception/card.php', 1).'?originid='.$object->id.'&origin=supplierorder">';
if (empty($conf->reception->enabled)) {
print '<form method="POST" action="dispatch.php?id='.$object->id.'">';
} else {
print '<form method="post" action="'.dol_buildpath('/reception/card.php', 1).'?originid='.$object->id.'&origin=supplierorder">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
if (empty($conf->reception->enabled))print '<input type="hidden" name="action" value="dispatch">';
else print '<input type="hidden" name="action" value="create">';
if (empty($conf->reception->enabled)) {
print '<input type="hidden" name="action" value="dispatch">';
} else {
print '<input type="hidden" name="action" value="create">';
}
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
@ -706,14 +682,17 @@ if ($id > 0 || !empty($ref)) {
$object,
$action
);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$sql .= $hookmanager->resPrint;
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid";
$sql .= " WHERE l.fk_commande = ".$object->id;
if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
$sql .= " AND l.product_type = 0";
}
// Enable hooks to alter the SQL query (WHERE)
$parameters = array();
@ -723,7 +702,9 @@ if ($id > 0 || !empty($ref)) {
$object,
$action
);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$sql .= $hookmanager->resPrint;
$sql .= " GROUP BY p.ref, p.label, p.tobatch, p.fk_default_warehouse, l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product
@ -785,7 +766,9 @@ if ($id > 0 || !empty($ref)) {
$object,
$action
);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
print $hookmanager->resPrint;
print "</tr>\n";
@ -803,8 +786,9 @@ if ($id > 0 || !empty($ref)) {
$nbfreeproduct++;
} else {
$remaintodispatch = price2num($objp->qty - ((float) $products_dispatched[$objp->rowid]), 5); // Calculation of dispatched
if ($remaintodispatch < 0)
if ($remaintodispatch < 0) {
$remaintodispatch = 0;
}
if ($remaintodispatch || empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) {
$nbproduct++;
@ -858,8 +842,9 @@ if ($id > 0 || !empty($ref)) {
// Define unit price for PMP calculation
$up_ht_disc = $objp->subprice;
if (!empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP))
if (!empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) {
$up_ht_disc = price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU');
}
// Supplier ref
print '<td class="right">'.$objp->sref.'</td>';
@ -892,7 +877,9 @@ if ($id > 0 || !empty($ref)) {
$object,
$action
);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
print $hookmanager->resPrint;
print '</tr>';
@ -903,8 +890,7 @@ if ($id > 0 || !empty($ref)) {
print '<input name="product_batch'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
if (!empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) // Not tested !
{
if (!empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) { // Not tested !
print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" type="text" value="'.price2num($up_ht_disc, 'MU').'">';
} else {
print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
@ -953,7 +939,9 @@ if ($id > 0 || !empty($ref)) {
$object,
$action
);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
print $hookmanager->resPrint;
print '</tr>';
@ -964,8 +952,7 @@ if ($id > 0 || !empty($ref)) {
print '<input name="product'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
if (!empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) // Not tested !
{
if (!empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) { // Not tested !
print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" type="text" value="'.price2num($up_ht_disc, 'MU').'">';
} else {
print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
@ -1030,7 +1017,9 @@ if ($id > 0 || !empty($ref)) {
$object,
$action
);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
print $hookmanager->resPrint;
print "</tr>\n";
@ -1046,16 +1035,14 @@ if ($id > 0 || !empty($ref)) {
print "</table>\n";
print '</div>';
if ($nbproduct)
{
if ($nbproduct) {
$checkboxlabel = $langs->trans("CloseReceivedSupplierOrdersAutomatically", $langs->transnoentitiesnoconv('StatusOrderReceivedAll'));
print '<div class="center">';
$parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
// modified by hook
if (empty($reshook))
{
if (empty($reshook)) {
if (empty($conf->reception->enabled)) {
print $langs->trans("Comment").' : ';
print '<input type="text" class="minwidth400" maxlength="128" name="comment" value="';
@ -1069,8 +1056,9 @@ if ($id > 0 || !empty($ref)) {
$dispatchBt = empty($conf->reception->enabled) ? $langs->trans("Receive") : $langs->trans("CreateReception");
print '<br><input type="submit" class="button" name="dispatch" value="'.dol_escape_htmltag($dispatchBt).'"';
if (count($listwarehouses) <= 0)
if (count($listwarehouses) <= 0) {
print ' disabled';
}
print '>';
}
print '</div>';
@ -1079,9 +1067,11 @@ if ($id > 0 || !empty($ref)) {
// Message if nothing to dispatch
if (!$nbproduct) {
print "<br>\n";
if (empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED))
if (empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) {
print '<div class="opacitymedium">'.$langs->trans("NoPredefinedProductToDispatch").'</div>'; // No predefined line at all
else print '<div class="opacitymedium">'.$langs->trans("NoMorePredefinedProductToDispatch").'</div>'; // No predefined line that remain to be dispatched.
} else {
print '<div class="opacitymedium">'.$langs->trans("NoMorePredefinedProductToDispatch").'</div>'; // No predefined line that remain to be dispatched.
}
}
print '</form>';
@ -1113,12 +1103,16 @@ if ($id > 0 || !empty($ref)) {
$sql .= " e.rowid as warehouse_id, e.ref as entrepot,";
$sql .= " cfd.rowid as dispatchlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.datec";
$sql .= " ,cd.rowid, cd.subprice";
if ($conf->reception->enabled)$sql .= " ,cfd.fk_reception, r.date_delivery";
if ($conf->reception->enabled) {
$sql .= " ,cfd.fk_reception, r.date_delivery";
}
$sql .= " FROM ".MAIN_DB_PREFIX."product as p,";
$sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as cd ON cd.rowid = cfd.fk_commandefourndet";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid";
if ($conf->reception->enabled)$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception as r ON cfd.fk_reception = r.rowid";
if ($conf->reception->enabled) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception as r ON cfd.fk_reception = r.rowid";
}
$sql .= " WHERE cfd.fk_commande = ".$object->id;
$sql .= " AND cfd.fk_product = p.rowid";
$sql .= " ORDER BY cfd.rowid ASC";
@ -1137,7 +1131,9 @@ if ($id > 0 || !empty($ref)) {
print '<table id="dispatch_received_products" class="noborder centpercent">';
print '<tr class="liste_titre">';
if ($conf->reception->enabled)print '<td>'.$langs->trans("Reception").'</td>';
if ($conf->reception->enabled) {
print '<td>'.$langs->trans("Reception").'</td>';
}
print '<td>'.$langs->trans("Product").'</td>';
print '<td>'.$langs->trans("DateCreation").'</td>';
@ -1169,8 +1165,7 @@ if ($id > 0 || !empty($ref)) {
while ($i < $num) {
$objp = $db->fetch_object($resql);
if ($action == 'editline' && $lineid == $objp->dispatchlineid)
{
if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
print '<form name="editdispatchedlines" id="editdispatchedlines" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#line_'.GETPOST('lineid').'" method="POST">
<input type="hidden" name="token" value="'.newToken().'">
<input type="hidden" name="action" value="updateline">
@ -1219,11 +1214,9 @@ if ($id > 0 || !empty($ref)) {
// Qty
print '<td class="right">';
if ($action == 'editline' && $lineid == $objp->dispatchlineid)
{
if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
print '<input style="width: 50px;" type="number" min="1" name="qty" value="'.$objp->qty.'" />';
}
else {
} else {
print $objp->qty;
}
print '<input type="hidden" name="price" value="'.$objp->subprice.'" />';
@ -1231,8 +1224,7 @@ if ($id > 0 || !empty($ref)) {
// Warehouse
print '<td>';
if ($action == 'editline' && $lineid == $objp->dispatchlineid)
{
if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
if (count($listwarehouses) > 1) {
print $formproduct->selectWarehouses(GETPOST("fk_entrepot") ?GETPOST("fk_entrepot") : ($objp->warehouse_id ? $objp->warehouse_id : ''), "fk_entrepot", '', 1, 0, $objp->fk_product, '', 1, 1, null, 'csswarehouse');
} elseif (count($listwarehouses) == 1) {
@ -1241,8 +1233,7 @@ if ($id > 0 || !empty($ref)) {
$langs->load("errors");
print $langs->trans("ErrorNoWarehouseDefined");
}
}
else {
} else {
$warehouse_static->id = $objp->warehouse_id;
$warehouse_static->libelle = $objp->entrepot;
print $warehouse_static->getNomUrl(1);
@ -1262,8 +1253,7 @@ if ($id > 0 || !empty($ref)) {
// Add button to check/uncheck disaptching
print '<td class="center">';
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))
{
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))) {
if (empty($objp->status)) {
print '<a class="button buttonRefused" href="#">'.$langs->trans("Approve").'</a>';
print '<a class="button buttonRefused" href="#">'.$langs->trans("Deny").'</a>';
@ -1273,8 +1263,9 @@ if ($id > 0 || !empty($ref)) {
}
} else {
$disabled = '';
if ($object->statut == 5)
if ($object->statut == 5) {
$disabled = 1;
}
if (empty($objp->status)) {
print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=checkdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Approve").'</a>';
print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=denydispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Deny").'</a>';
@ -1297,8 +1288,7 @@ if ($id > 0 || !empty($ref)) {
print '</td>';
}
if ($action != 'editline' || $lineid != $objp->dispatchlineid)
{
if ($action != 'editline' || $lineid != $objp->dispatchlineid) {
print '<td class="linecoledit center">';
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;lineid='.$objp->dispatchlineid.'#line_'.$objp->dispatchlineid.'">';
print img_edit();
@ -1310,8 +1300,7 @@ if ($id > 0 || !empty($ref)) {
print img_delete();
print '</a>';
print '</td>';
}
else {
} else {
print '<td class="center valignmiddle">';
print '<input type="submit" class="button button-save" id="savelinebutton" name="save" value="'.$langs->trans("Save").'" />';
print '</td>';
@ -1322,7 +1311,9 @@ if ($id > 0 || !empty($ref)) {
print "</tr>\n";
if ($action == 'editline' && $lineid == $objp->dispatchlineid) print '</form>';
if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
print '</form>';
}
$i++;
}

View File

@ -47,7 +47,9 @@ $action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande');
// Get parameters
@ -55,17 +57,22 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
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
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) $sortfield = "name";
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "name";
}
$object = new CommandeFournisseur($db);
if ($object->fetch($id, $ref) < 0)
{
if ($object->fetch($id, $ref) < 0) {
dol_print_error($db);
exit;
}
@ -87,8 +94,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
$form = new Form($db);
if ($object->id > 0)
{
if ($object->id > 0) {
$help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
llxHeader('', $langs->trans("Order"), $help_url);
@ -105,8 +111,7 @@ if ($object->id > 0)
// Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$totalsize = 0;
foreach ($filearray as $key => $file)
{
foreach ($filearray as $key => $file) {
$totalsize += $file['size'];
}
@ -121,12 +126,10 @@ if ($object->id > 0)
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->fournisseur->commande->creer)
{
if ($user->rights->fournisseur->commande->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref .= ' : ';

View File

@ -32,7 +32,9 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
// Security check
$orderid = GETPOST('orderid');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'fournisseur', $orderid, '', 'commande');
$hookmanager = new HookManager($db);
@ -59,8 +61,7 @@ print load_fiche_titre($langs->trans("SuppliersOrdersArea"), '', 'supplier_order
print '<div class="fichecenter"><div class="fichethirdleft">';
if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
{
if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is useless due to the global search combo
print '<form method="post" action="list.php">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<div class="div-table-responsive-no-min">';
@ -79,16 +80,21 @@ if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useles
$sql = "SELECT count(cf.rowid) as nb, fk_statut as status";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE cf.fk_soc = s.rowid";
$sql .= " AND cf.entity IN (".getEntity('supplier_order').")";
if ($user->socid) $sql .= ' AND cf.fk_soc = '.$user->socid;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($user->socid) {
$sql .= ' AND cf.fk_soc = '.$user->socid;
}
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
$sql .= " GROUP BY cf.fk_statut";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -98,11 +104,9 @@ if ($resql)
// 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially
// -> 7=Canceled/Never received -> (reopen) 3=Process runing
// -> 6=Canceled -> (reopen) 2=Approved
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
if ($obj)
{
if ($obj) {
$vals[($obj->status == CommandeFournisseur::STATUS_CANCELED_AFTER_ORDER ? CommandeFournisseur::STATUS_CANCELED : $obj->status)] = $obj->nb;
$total += $obj->nb;
@ -118,28 +122,41 @@ if ($resql)
print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("SuppliersOrders").'</th></tr>';
print "</tr>\n";
$listofstatus = array(0, 1, 2, 3, 4, 5, 6, 9);
foreach ($listofstatus as $status)
{
foreach ($listofstatus as $status) {
$dataseries[] = array($commandestatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
if ($status == CommandeFournisseur::STATUS_DRAFT) $colorseries[$status] = '-'.$badgeStatus0;
if ($status == CommandeFournisseur::STATUS_VALIDATED) $colorseries[$status] = '-'.$badgeStatus1;
if ($status == CommandeFournisseur::STATUS_ACCEPTED) $colorseries[$status] = $badgeStatus1;
if ($status == CommandeFournisseur::STATUS_REFUSED) $colorseries[$status] = $badgeStatus9;
if ($status == CommandeFournisseur::STATUS_ORDERSENT) $colorseries[$status] = $badgeStatus4;
if ($status == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY) $colorseries[$status] = '-'.$badgeStatus4;
if ($status == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) $colorseries[$status] = $badgeStatus6;
if ($status == CommandeFournisseur::STATUS_CANCELED || $status == CommandeFournisseur::STATUS_CANCELED_AFTER_ORDER) $colorseries[$status] = $badgeStatus9;
if ($status == CommandeFournisseur::STATUS_DRAFT) {
$colorseries[$status] = '-'.$badgeStatus0;
}
if ($status == CommandeFournisseur::STATUS_VALIDATED) {
$colorseries[$status] = '-'.$badgeStatus1;
}
if ($status == CommandeFournisseur::STATUS_ACCEPTED) {
$colorseries[$status] = $badgeStatus1;
}
if ($status == CommandeFournisseur::STATUS_REFUSED) {
$colorseries[$status] = $badgeStatus9;
}
if ($status == CommandeFournisseur::STATUS_ORDERSENT) {
$colorseries[$status] = $badgeStatus4;
}
if ($status == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY) {
$colorseries[$status] = '-'.$badgeStatus4;
}
if ($status == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) {
$colorseries[$status] = $badgeStatus6;
}
if ($status == CommandeFournisseur::STATUS_CANCELED || $status == CommandeFournisseur::STATUS_CANCELED_AFTER_ORDER) {
$colorseries[$status] = $badgeStatus9;
}
if (!$conf->use_javascript_ajax)
{
if (!$conf->use_javascript_ajax) {
print '<tr class="oddeven">';
print '<td>'.$commandestatic->LibStatut($status, 0).'</td>';
print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
print "</tr>\n";
}
}
if ($conf->use_javascript_ajax)
{
if ($conf->use_javascript_ajax) {
print '<tr class="impair"><td class="center" colspan="2">';
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
@ -168,32 +185,34 @@ if ($resql)
* Draft orders
*/
if (!empty($conf->fournisseur->enabled))
{
if (!empty($conf->fournisseur->enabled)) {
$sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE c.fk_soc = s.rowid";
$sql .= " AND c.entity IN (".getEntity("supplier_order").")"; // Thirdparty sharing is mandatory with supplier order sharing
$sql .= " AND c.fk_statut = 0";
if (!empty($socid)) $sql .= " AND c.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if (!empty($socid)) {
$sql .= " AND c.fk_soc = ".$socid;
}
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
$langs->load("orders");
$num = $db->num_rows($resql);
if ($num)
{
if ($num) {
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
@ -218,8 +237,7 @@ if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_T
}
$sql .= " u.rowid, u.lastname, u.firstname, u.email, u.statut";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
{
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug";
$sql .= " WHERE ((ug.fk_user = u.rowid";
$sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
@ -230,8 +248,7 @@ if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_T
$sql .= " AND u.fk_soc IS NULL"; // An external user can not approved
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -240,16 +257,14 @@ if ($resql)
print '<tr class="liste_titre"><th>'.$langs->trans("UserWithApproveOrderGrant").'</th>';
print "</tr>\n";
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
$userstatic = new User($db);
$userstatic->id = $obj->rowid;
$userstatic->getrights('fournisseur');
if (!empty($userstatic->rights->fournisseur->commande->approuver))
{
if (!empty($userstatic->rights->fournisseur->commande->approuver)) {
print '<tr class="oddeven">';
print '<td>';
$userstatic->lastname = $obj->lastname;
@ -281,29 +296,32 @@ $max = 5;
$sql = "SELECT c.rowid, c.ref, c.fk_statut as status, c.tms, c.billed, s.nom as name, s.rowid as socid";
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE c.fk_soc = s.rowid";
$sql .= " AND c.entity = ".$conf->entity;
//$sql.= " AND c.fk_statut > 2";
if (!empty($socid)) $sql .= " AND c.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if (!empty($socid)) {
$sql .= " AND c.fk_soc = ".$socid;
}
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
$sql .= " ORDER BY c.tms DESC";
$sql .= $db->plimit($max, 0);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th colspan="4">'.$langs->trans("LastModifiedOrders", $max).'</th></tr>';
$num = $db->num_rows($resql);
if ($num)
{
if ($num) {
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
@ -338,7 +356,9 @@ if ($resql)
}
}
print "</table></div><br>";
} else dol_print_error($db);
} else {
dol_print_error($db);
}
/*

View File

@ -44,17 +44,24 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOST("page", 'int');
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
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortfield) $sortfield = 'a.datep,a.id';
if (!$sortorder) $sortorder = 'DESC,DESC';
if (!$sortfield) {
$sortfield = 'a.datep,a.id';
}
if (!$sortorder) {
$sortorder = 'DESC,DESC';
}
if (GETPOST('actioncode', 'array'))
{
if (GETPOST('actioncode', 'array')) {
$actioncode = GETPOST('actioncode', 'array', 3);
if (!count($actioncode)) $actioncode = '0';
if (!count($actioncode)) {
$actioncode = '0';
}
} else {
$actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECTS) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECTS));
}
@ -62,10 +69,14 @@ $search_agenda_label = GETPOST('search_agenda_label');
// Security check
$socid = 0;
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande');
if (!$user->rights->fournisseur->commande->lire) accessforbidden();
if (!$user->rights->fournisseur->commande->lire) {
accessforbidden();
}
@ -76,11 +87,12 @@ if (!$user->rights->fournisseur->commande->lire) accessforbidden();
$parameters = array('id'=>$id);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
// Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All test are required to be compatible with all browsers
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
$actioncode = '';
$search_agenda_label = '';
}
@ -94,15 +106,16 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
$form = new Form($db);
$object = new CommandeFournisseur($db);
if ($id > 0 || !empty($ref))
{
if ($id > 0 || !empty($ref)) {
$object->fetch($id, $ref);
$object->fetch_thirdparty();
$object->info($object->id);
}
$title = $langs->trans("SupplierOrder").' - '.$object->ref.' '.$object->name;
if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->ref.' '.$object->name.' - '.$langs->trans("Info");
if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
$title = $object->ref.' '.$object->name.' - '.$langs->trans("Info");
}
$help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
llxHeader('', $title, $help_url);
@ -125,12 +138,10 @@ $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->fournisseur->commande->creer)
{
if ($user->rights->fournisseur->commande->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref .= ' : ';
@ -181,18 +192,15 @@ print dol_get_fiche_end();
$out = '';
$permok = $user->rights->agenda->myactions->create;
if ($permok)
{
if ($permok) {
$out .= '&originid='.$object->id.'&origin=order_supplier';
}
print '<div class="tabsAction">';
if (!empty($conf->agenda->enabled))
{
if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create))
{
if (!empty($conf->agenda->enabled)) {
if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'">'.$langs->trans("AddAction").'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
@ -202,18 +210,21 @@ if (!empty($conf->agenda->enabled))
print '</div>';
if (!empty($object->id))
{
if (!empty($object->id)) {
$param = '&id='.$object->id;
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.$contextpage;
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.$limit;
}
print load_fiche_titre($langs->trans("ActionsOnOrder"), '', '');
// List of actions on element
/*include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
$formactions=new FormActions($db);
$somethingshown = $formactions->showactions($object,'project',0);*/
$formactions=new FormActions($db);
$somethingshown = $formactions->showactions($object,'project',0);*/
// List of todo actions
//show_actions_todo($conf,$langs,$db,$object,null,0,$actioncode);

File diff suppressed because it is too large Load Diff

View File

@ -40,7 +40,9 @@ $ref = GETPOST('ref');
$action = GETPOST('action', 'aZ09');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande');
$object = new CommandeFournisseur($db);
@ -72,10 +74,8 @@ $form = new Form($db);
$now = dol_now();
if ($id > 0 || !empty($ref))
{
if ($result >= 0)
{
if ($id > 0 || !empty($ref)) {
if ($result >= 0) {
$object->fetch_thirdparty();
$author = new User($db);
@ -97,12 +97,10 @@ if ($id > 0 || !empty($ref))
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->fournisseur->commande->creer)
{
if ($user->rights->fournisseur->commande->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref .= ' : ';

View File

@ -17,8 +17,7 @@
*/
// Protection to avoid direct call of template
if (empty($conf) || !is_object($conf))
{
if (empty($conf) || !is_object($conf)) {
print "Error, template page can't be called as URL";
exit;
}
@ -37,41 +36,41 @@ $langs->load("orders");
$total = 0;
$ilink = 0;
foreach ($linkedObjectBlock as $key => $objectlink)
{
foreach ($linkedObjectBlock as $key => $objectlink) {
$ilink++;
$trclass = 'oddeven';
if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass .= ' liste_sub_total';
if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) {
$trclass .= ' liste_sub_total';
}
?>
<tr class="<?php echo $trclass; ?>">
<td><?php echo $langs->trans("SupplierOrder"); ?></td>
<td><a href="<?php echo DOL_URL_ROOT.'/fourn/commande/card.php?id='.$objectlink->id ?>"><?php echo img_object($langs->trans("ShowOrder"), "order").' '.$objectlink->ref; ?></a></td>
<td class="left"><?php echo $objectlink->ref_supplier; ?></td>
<td class="center"><?php echo dol_print_date($objectlink->date, 'day'); ?></td>
<td class="right"><?php
<tr class="<?php echo $trclass; ?>">
<td><?php echo $langs->trans("SupplierOrder"); ?></td>
<td><a href="<?php echo DOL_URL_ROOT.'/fourn/commande/card.php?id='.$objectlink->id ?>"><?php echo img_object($langs->trans("ShowOrder"), "order").' '.$objectlink->ref; ?></a></td>
<td class="left"><?php echo $objectlink->ref_supplier; ?></td>
<td class="center"><?php echo dol_print_date($objectlink->date, 'day'); ?></td>
<td class="right"><?php
if ($user->rights->fournisseur->commande->lire) {
$total = $total + $objectlink->total_ht;
echo price($objectlink->total_ht);
} ?></td>
<td class="right"><?php echo $objectlink->getLibStatut(3); ?></td>
<td class="right"><a class="reposition" href="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dellink&dellinkid='.$key; ?>"><?php echo img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink'); ?></a></td>
</tr>
<td class="right"><?php echo $objectlink->getLibStatut(3); ?></td>
<td class="right"><a class="reposition" href="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dellink&dellinkid='.$key; ?>"><?php echo img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink'); ?></a></td>
</tr>
<?php
}
if (count($linkedObjectBlock) > 1)
{
if (count($linkedObjectBlock) > 1) {
?>
<tr class="liste_total <?php echo (empty($noMoreLinkedObjectBlockAfter) ? 'liste_sub_total' : ''); ?>">
<td><?php echo $langs->trans("Total"); ?></td>
<td></td>
<td class="center"></td>
<td class="center"></td>
<td class="right"><?php echo price($total); ?></td>
<td class="right"></td>
<td class="right"></td>
</tr>
<?php
<tr class="liste_total <?php echo (empty($noMoreLinkedObjectBlockAfter) ? 'liste_sub_total' : ''); ?>">
<td><?php echo $langs->trans("Total"); ?></td>
<td></td>
<td class="center"></td>
<td class="center"></td>
<td class="right"><?php echo price($total); ?></td>
<td class="right"></td>
<td class="right"></td>
</tr>
<?php
}
print "<!-- END PHP TEMPLATE -->\n";

View File

@ -35,8 +35,7 @@ $langs->load("companies");
llxHeader();
// Security check
if ($user->socid > 0)
{
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
@ -45,12 +44,18 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
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
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) $sortfield = "p.name";
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "p.name";
}
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
@ -59,14 +64,20 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
*/
$sql = "SELECT s.rowid as socid, s.nom as name, st.libelle as stcomm, p.rowid as cidp, p.lastname, p.firstname, p.email, p.phone";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", sc.fk_soc, sc.fk_user ";
}
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."socpeople as p, ".MAIN_DB_PREFIX."c_stcomm as st";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.fk_stcomm = st.id";
$sql .= " AND s.fournisseur = 1";
$sql .= " AND s.rowid = p.fk_soc";
$sql .= " AND s.entity IN (".getEntity('societe').")";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if (dol_strlen($stcomm)) {
$sql .= " AND s.fk_stcomm=$stcomm";
@ -90,8 +101,7 @@ $sql .= " ORDER BY $sortfield $sortorder ";
$sql .= $db->plimit($limit, $offset);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
@ -107,8 +117,7 @@ if ($result)
print "</tr>\n";
$i = 0;
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($result);
print '<tr class="oddeven">';

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,9 @@ $ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
$object = new FactureFournisseur($db);
@ -51,51 +53,39 @@ $object = new FactureFournisseur($db);
* Ajout d'un nouveau contact
*/
if ($action == 'addcontact' && $user->rights->fournisseur->facture->creer)
{
if ($action == 'addcontact' && $user->rights->fournisseur->facture->creer) {
$result = $object->fetch($id, $ref);
if ($result > 0 && $id > 0)
{
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)
{
if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
} else {
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
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))
{
} elseif ($action == 'swapstatut' && $user->rights->fournisseur->facture->creer) {
// bascule du statut d'un contact
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)
{
} elseif ($action == 'deletecontact' && $user->rights->fournisseur->facture->creer) {
// Efface un contact
$object->fetch($id);
$result = $object->delete_contact($_GET["lineid"]);
if ($result >= 0)
{
if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
} else {
@ -124,10 +114,8 @@ $userstatic = new User($db);
/* */
/* *************************************************************************** */
if ($id > 0 || !empty($ref))
{
if ($object->fetch($id, $ref) > 0)
{
if ($id > 0 || !empty($ref)) {
if ($object->fetch($id, $ref) > 0) {
$object->fetch_thirdparty();
$alreadypaid = $object->getSommePaiement();
@ -144,17 +132,18 @@ if ($id > 0 || !empty($ref))
$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
$morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
}
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->facture->creer)
{
if ($action != 'classify')
if ($user->rights->facture->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$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 .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
@ -192,36 +181,34 @@ if ($id > 0 || !empty($ref))
// Type
print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td colspan="4">';
print $object->getLibType();
if ($object->type == FactureFournisseur::TYPE_REPLACEMENT)
{
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->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)
{
if (count($facidavoir) > 0) {
print ' ('.$langs->transnoentities("InvoiceHasAvoir");
$i = 0;
foreach ($facidavoir as $fid)
{
if ($i == 0) print ' ';
else print ',';
foreach ($facidavoir as $fid) {
if ($i == 0) {
print ' ';
} else {
print ',';
}
$facavoir = new FactureFournisseur($db);
$facavoir->fetch($fid);
print $facavoir->getNomUrl(1);
}
print ')';
}
if ($facidnext > 0)
{
if ($facidnext > 0) {
$facthatreplace = new FactureFournisseur($db);
$facthatreplace->fetch($facidnext);
print ' ('.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)).')';
@ -239,14 +226,12 @@ if ($id > 0 || !empty($ref))
// Amount Local Taxes
//TODO: Place into a function to control showing by country or study better option
if ($societe->localtax1_assuj == "1") //Localtax1
{
if ($societe->localtax1_assuj == "1") { //Localtax1
print '<tr><td>'.$langs->transcountry("AmountLT1", $societe->country_code).'</td>';
print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
print '</tr>';
}
if ($societe->localtax2_assuj == "1") //Localtax2
{
if ($societe->localtax2_assuj == "1") { //Localtax2
print '<tr><td>'.$langs->transcountry("AmountLT2", $societe->country_code).'</td>';
print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
print '</tr>';

View File

@ -46,7 +46,9 @@ $confirm = GETPOST('confirm', 'alpha');
$ref = GETPOST('ref', 'alpha');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
// Get parameters
@ -54,16 +56,21 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
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
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) $sortfield = "name";
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "name";
}
$object = new FactureFournisseur($db);
if ($object->fetch($id, $ref))
{
if ($object->fetch($id, $ref)) {
$object->fetch_thirdparty();
$ref = dol_sanitizeFileName($object->ref);
$upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$ref;
@ -87,8 +94,7 @@ $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('Documents');
$helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
llxHeader('', $title, $helpurl);
if ($object->id > 0)
{
if ($object->id > 0) {
$head = facturefourn_prepare_head($object);
print dol_get_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice');
@ -102,17 +108,18 @@ if ($object->id > 0)
$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
$morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
}
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->facture->creer)
{
if ($action != 'classify')
if ($user->rights->facture->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$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 .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
@ -148,16 +155,14 @@ if ($object->id > 0)
// Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$totalsize = 0;
foreach ($filearray as $key => $file)
{
foreach ($filearray as $key => $file) {
$totalsize += $file['size'];
}
/*
* Confirm delete file
*/
if ($action == 'delete')
{
if ($action == 'delete') {
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
}
@ -166,28 +171,27 @@ if ($object->id > 0)
// Type
print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
print $object->getLibType();
if ($object->type == FactureFournisseur::TYPE_REPLACEMENT)
{
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->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)
{
if (count($facidavoir) > 0) {
print ' ('.$langs->transnoentities("InvoiceHasAvoir");
$i = 0;
foreach ($facidavoir as $id)
{
if ($i == 0) print ' ';
else print ',';
foreach ($facidavoir as $id) {
if ($i == 0) {
print ' ';
} else {
print ',';
}
$facavoir = new FactureFournisseur($db);
$facavoir->fetch($id);
print $facavoir->getNomUrl(1);
@ -215,14 +219,12 @@ if ($object->id > 0)
// Amount Local Taxes
//TODO: Place into a function to control showing by country or study better option
if ($mysoc->localtax1_assuj == "1") //Localtax1
{
if ($mysoc->localtax1_assuj == "1") { //Localtax1
print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
print '</tr>';
}
if ($mysoc->localtax2_assuj == "1") //Localtax2
{
if ($mysoc->localtax2_assuj == "1") { //Localtax2
print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
print '</tr>';
@ -255,8 +257,7 @@ if ($object->id > 0)
$defaulttpldir = '/core/tpl';
$dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir));
foreach ($dirtpls as $module => $reldir)
{
foreach ($dirtpls as $module => $reldir) {
if (!empty($module)) {
$tpl = dol_buildpath($reldir.'/document_actions_post_headers.tpl.php');
} else {
@ -268,7 +269,9 @@ if ($object->id > 0)
} else {
$res = include $tpl; // for debug
}
if ($res) break;
if ($res) {
break;
}
}
} else {
print $langs->trans('ErrorUnknown');

View File

@ -31,7 +31,9 @@ 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();
if (!$user->rights->fournisseur->facture->lire) {
accessforbidden();
}
$langs->loadLangs(array("companies", "bills"));
@ -39,8 +41,7 @@ $socid = GETPOST('socid', 'int');
$option = GETPOST('option');
// Security check
if ($user->socid > 0)
{
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
@ -56,15 +57,20 @@ $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
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 (!$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
{
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 = "";
@ -85,101 +91,124 @@ $title = $langs->trans("BillsSuppliersUnpaid");
$facturestatic = new FactureFournisseur($db);
$companystatic = new Societe($db);
if ($user->rights->fournisseur->facture->lire)
{
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 ";
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";
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 ($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'))
{
if (GETPOST('filtre')) {
$filtrearr = explode(",", GETPOST('filtre'));
foreach ($filtrearr as $fil)
{
foreach ($filtrearr as $fil) {
$filt = explode(":", $fil);
$sql .= " AND ".$filt[0]." = ".$filt[1];
}
}
if ($search_ref)
{
if ($search_ref) {
$sql .= " AND f.ref LIKE '%".$db->escape($search_ref)."%'";
}
if ($search_ref_supplier)
{
if ($search_ref_supplier) {
$sql .= " AND f.ref_supplier LIKE '%".$db->escape($search_ref_supplier)."%'";
}
if ($search_company)
{
if ($search_company) {
$sql .= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
}
if ($search_amount_no_tax)
{
if ($search_amount_no_tax) {
$sql .= " AND f.total_ht = '".$db->escape($search_amount_no_tax)."'";
}
if ($search_amount_all_tax)
{
if ($search_amount_all_tax) {
$sql .= " AND f.total_ttc = '".$db->escape($search_amount_all_tax)."'";
}
if (dol_strlen(GETPOST('sf_re')) > 0)
{
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 ";
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";
if (!in_array("f.ref_supplier", explode(',', $sortfield))) {
$sql .= ", f.ref_supplier DESC";
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
if ($socid)
{
if ($socid) {
$soc = new Societe($db);
$soc->fetch($socid);
}
$param = '';
if ($socid) $param .= "&socid=".$socid;
if ($socid) {
$param .= "&socid=".$socid;
}
if ($search_ref) $param .= '&amp;search_ref='.urlencode($search_ref);
if ($search_ref_supplier) $param .= '&amp;search_ref_supplier='.urlencode($search_ref_supplier);
if ($search_company) $param .= '&amp;search_company='.urlencode($search_company);
if ($search_amount_no_tax) $param .= '&amp;search_amount_no_tax='.urlencode($search_amount_no_tax);
if ($search_amount_all_tax) $param .= '&amp;search_amount_all_tax='.urlencode($search_amount_all_tax);
if ($search_ref) {
$param .= '&amp;search_ref='.urlencode($search_ref);
}
if ($search_ref_supplier) {
$param .= '&amp;search_ref_supplier='.urlencode($search_ref_supplier);
}
if ($search_company) {
$param .= '&amp;search_company='.urlencode($search_company);
}
if ($search_amount_no_tax) {
$param .= '&amp;search_amount_no_tax='.urlencode($search_amount_no_tax);
}
if ($search_amount_all_tax) {
$param .= '&amp;search_amount_all_tax='.urlencode($search_amount_all_tax);
}
$param .= ($option ? "&option=".$option : "");
if (!empty($late)) $param .= '&late='.urlencode($late);
if (!empty($late)) {
$param .= '&late='.urlencode($late);
}
$urlsource = str_replace('&amp;', '&', $param);
$titre = ($socid ? $langs->trans("BillsSuppliersUnpaidForCompany", $soc->name) : $langs->trans("BillsSuppliersUnpaid"));
if ($option == 'late') $titre .= ' ('.$langs->trans("Late").')';
else $titre .= ' ('.$langs->trans("All").')';
if ($option == 'late') {
$titre .= ' ('.$langs->trans("Late").')';
} else {
$titre .= ' ('.$langs->trans("All").')';
}
$link = '';
if (empty($option)) $link = '<a href="'.$_SERVER["PHP_SELF"].'?option=late'.($socid ? '&socid='.$socid : '').'">'.$langs->trans("ShowUnpaidLateOnly").'</a>';
elseif ($option == 'late') $link = '<a href="'.$_SERVER["PHP_SELF"].'?'.($socid ? '&socid='.$socid : '').'">'.$langs->trans("ShowUnpaidAll").'</a>';
if (empty($option)) {
$link = '<a href="'.$_SERVER["PHP_SELF"].'?option=late'.($socid ? '&socid='.$socid : '').'">'.$langs->trans("ShowUnpaidLateOnly").'</a>';
} elseif ($option == 'late') {
$link = '<a href="'.$_SERVER["PHP_SELF"].'?'.($socid ? '&socid='.$socid : '').'">'.$langs->trans("ShowUnpaidAll").'</a>';
}
print load_fiche_titre($titre, $link);
print_barre_liste('', '', $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', 0); // We don't want pagination on this page
@ -220,14 +249,12 @@ if ($user->rights->fournisseur->facture->lire)
print '</td>';
print "</tr>\n";
if ($num > 0)
{
if ($num > 0) {
$total_ht = 0;
$total_ttc = 0;
$total_paid = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $db->fetch_object($resql);
$facturestatic->statut = $objp->fk_statut;

View File

@ -34,8 +34,7 @@ $langs->loadLangs(['bills', 'boxes']);
// Filter to show only result of one supplier
$socid = GETPOST('socid', 'int');
if (isset($user->socid) && $user->socid > 0)
{
if (isset($user->socid) && $user->socid > 0) {
$action = '';
$socid = $user->socid;
}
@ -58,8 +57,7 @@ print '<div class="fichecenter">';
print '<div class="fichethirdleft">';
// This is useless due to the global search combo
if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))
{
if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) {
print getAreaSearchFrom();
print '<br>';
}
@ -129,16 +127,21 @@ function getPieChart($socid = 0)
$sql = "SELECT count(f.rowid), f.fk_statut";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
if ($user->socid) $sql .= ' AND f.fk_soc = '.$user->socid;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($user->socid) {
$sql .= ' AND f.fk_soc = '.$user->socid;
}
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
$sql .= " GROUP BY f.fk_statut";
$resql = $db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($db);
return '';
}
@ -149,11 +152,9 @@ function getPieChart($socid = 0)
$total = 0;
$vals = [];
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
if ($row)
{
if ($row) {
$vals[$row[1]] = $row[0];
$total += $row[0];
}
@ -174,14 +175,12 @@ function getPieChart($socid = 0)
$array = [FactureFournisseur::STATUS_DRAFT, FactureFournisseur::STATUS_VALIDATED, FactureFournisseur::STATUS_CLOSED, FactureFournisseur::STATUS_ABANDONED];
$dataseries = [];
foreach ($array as $status)
{
foreach ($array as $status) {
$objectstatic->statut = $status;
$objectstatic->paye = $status == FactureFournisseur::STATUS_CLOSED ? -1 : 0;
$dataseries[] = [$objectstatic->getLibStatut(1), (isset($vals[$status]) ? (int) $vals[$status] : 0)];
if (!$conf->use_javascript_ajax)
{
if (!$conf->use_javascript_ajax) {
$result .= '<tr class="oddeven">';
$result .= '<td>'.$objectstatic->getLibStatut(0).'</td>';
$result .= '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
@ -189,8 +188,7 @@ function getPieChart($socid = 0)
}
}
if ($conf->use_javascript_ajax)
{
if ($conf->use_javascript_ajax) {
$dolgraph = new DolGraph();
$dolgraph->SetData($dataseries);
$dolgraph->setShowLegend(2);
@ -229,17 +227,22 @@ function getDraftTable($maxCount = 500, $socid = 0)
$sql = "SELECT f.rowid, f.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client, f.total_ttc";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
$sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
$sql .= $db->plimit($maxCount, 0);
$resql = $db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($db);
return '';
}
@ -258,8 +261,7 @@ function getDraftTable($maxCount = 500, $socid = 0)
$result .= '</td>';
$result .= '</tr>';
if ($num < 1)
{
if ($num < 1) {
$result .= '</table>';
$result .= '</div>';
return $result;
@ -271,8 +273,7 @@ function getDraftTable($maxCount = 500, $socid = 0)
$total = 0;
$i = 0;
while ($i < $nbofloop)
{
while ($i < $nbofloop) {
$obj = $db->fetch_object($resql);
$objectstatic->id = $obj->rowid;
@ -293,14 +294,11 @@ function getDraftTable($maxCount = 500, $socid = 0)
$total += $obj->total_ttc;
}
if ($num > $nbofloop)
{
if ($num > $nbofloop) {
$result .= '<tr class="liste_total">';
$result .= '<td colspan="3" class="right">'.$langs->trans("XMoreLines", ($num - $nbofloop)).'</td>';
$result .= '</tr>';
}
elseif ($total > 0)
{
} elseif ($total > 0) {
$result .= '<tr class="liste_total">';
$result .= '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
$result .= '<td class="right">'.price($total).'</td>';
@ -327,17 +325,22 @@ function getLatestEditTable($maxCount = 5, $socid = 0)
$sql .= " f.datec";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
$sql .= " ORDER BY f.tms DESC";
$sql .= $db->plimit($maxCount, 0);
$resql = $db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($db);
return '';
}
@ -350,8 +353,7 @@ function getLatestEditTable($maxCount = 5, $socid = 0)
$result .= '<td colspan="4">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).'</td>';
$result .= '</tr>';
if ($num < 1)
{
if ($num < 1) {
$result .= '</table>';
$result .= '</div>';
return $result;
@ -362,8 +364,7 @@ function getLatestEditTable($maxCount = 5, $socid = 0)
$formfile = new FormFile($db);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
$objectstatic->id = $obj->rowid;
@ -423,18 +424,23 @@ function getOpenTable($maxCount = 500, $socid = 0)
$sql .= ", f.datef as df, f.date_lim_reglement as datelimite";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
$sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
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 (!$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;
}
$sql .= " ORDER BY f.rowid DESC";
$sql .= $db->plimit($maxCount, 0);
$resql = $db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($db);
return '';
}
@ -452,8 +458,7 @@ function getOpenTable($maxCount = 500, $socid = 0)
$result .= '</td>';
$result .= '</tr>';
if ($num < 1)
{
if ($num < 1) {
$result .= '</table>';
$result .= '</div>';
return $result;
@ -467,8 +472,7 @@ function getOpenTable($maxCount = 500, $socid = 0)
$total = 0;
$i = 0;
while ($i < $nbofloop)
{
while ($i < $nbofloop) {
$obj = $db->fetch_object($resql);
$objectstatic->id = $obj->id;
@ -491,8 +495,7 @@ function getOpenTable($maxCount = 500, $socid = 0)
$result .= '<td class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
$result .= '<td width="18" class="nobordernopadding nowrap">';
if ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay))
{
if ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) {
$result .= img_warning($langs->trans("Late"));
}
@ -514,14 +517,11 @@ function getOpenTable($maxCount = 500, $socid = 0)
$total += $obj->total_ttc;
}
if ($num > $nbofloop)
{
if ($num > $nbofloop) {
$result .= '<tr class="liste_total">';
$result .= '<td colspan="4" class="right">'.$langs->trans("XMoreLines", ($num - $nbofloop)).'</td>';
$result .= '</tr>';
}
elseif ($total > 0)
{
} elseif ($total > 0) {
$result .= '<tr class="liste_total">';
$result .= '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
$result .= '<td align="right">'.price($total).'</td>';

View File

@ -40,7 +40,9 @@ $id = GETPOST("facid", 'int') ?GETPOST("facid", 'int') : GETPOST("id", 'int');
$ref = GETPOST("ref", 'alpha');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
$object = new FactureFournisseur($db);
@ -75,39 +77,40 @@ $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_
$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
$morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
}
// Project
if (!empty($conf->projet->enabled))
{
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->facture->creer)
{
if ($action != 'classify')
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$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 .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
$morehtmlref .= '<input type="hidden" name="action" value="classin">';
$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
$morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref .= '</form>';
} 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 .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
$morehtmlref .= $proj->ref;
$morehtmlref .= '</a>';
} else {
$morehtmlref .= '';
}
}
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->facture->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$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 .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
$morehtmlref .= '<input type="hidden" name="action" value="classin">';
$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
$morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref .= '</form>';
} 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 .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
$morehtmlref .= $proj->ref;
$morehtmlref .= '</a>';
} else {
$morehtmlref .= '';
}
}
}
$morehtmlref .= '</div>';

File diff suppressed because it is too large Load Diff

View File

@ -40,7 +40,9 @@ $ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
$object = new FactureFournisseur($db);
@ -56,11 +58,12 @@ $permissionnote = $user->rights->fournisseur->facture->creer; // Used by the inc
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
// Set label
if ($action == 'setlabel' && $user->rights->fournisseur->facture->creer)
{
if ($action == 'setlabel' && $user->rights->fournisseur->facture->creer) {
$object->label = $_POST['label'];
$result = $object->update($user);
if ($result < 0) dol_print_error($db);
if ($result < 0) {
dol_print_error($db);
}
}
@ -74,8 +77,7 @@ $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('Notes');
$helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
llxHeader('', $title, $helpurl);
if ($object->id > 0)
{
if ($object->id > 0) {
$object->fetch_thirdparty();
$alreadypaid = $object->getSommePaiement();
@ -94,14 +96,14 @@ if ($object->id > 0)
$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
$morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
}
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->fournisseur->commande->creer)
{
if ($user->rights->fournisseur->commande->creer) {
if ($action != 'classify') {
// $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref .= ' : ';
@ -143,36 +145,34 @@ if ($object->id > 0)
// Type
print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
print $object->getLibType();
if ($object->type == FactureFournisseur::TYPE_REPLACEMENT)
{
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->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)
{
if (count($facidavoir) > 0) {
print ' ('.$langs->transnoentities("InvoiceHasAvoir");
$i = 0;
foreach ($facidavoir as $fid)
{
if ($i == 0) print ' ';
else print ',';
foreach ($facidavoir as $fid) {
if ($i == 0) {
print ' ';
} else {
print ',';
}
$facavoir = new FactureFournisseur($db);
$facavoir->fetch($fid);
print $facavoir->getNomUrl(1);
}
print ')';
}
if ($facidnext > 0)
{
if ($facidnext > 0) {
$facthatreplace = new FactureFournisseur($db);
$facthatreplace->fetch($facidnext);
print ' ('.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)).')';
@ -190,14 +190,12 @@ if ($object->id > 0)
// Amount Local Taxes
//TODO: Place into a function to control showing by country or study better option
if ($societe->localtax1_assuj == "1") //Localtax1
{
if ($societe->localtax1_assuj == "1") { //Localtax1
print '<tr><td>'.$langs->transcountry("AmountLT1", $societe->country_code).'</td>';
print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
print '</tr>';
}
if ($societe->localtax2_assuj == "1") //Localtax2
{
if ($societe->localtax2_assuj == "1") { //Localtax2
print '<tr><td>'.$langs->transcountry("AmountLT2", $societe->country_code).'</td>';
print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
print '</tr>';

View File

@ -64,12 +64,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
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
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "p.rowid";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "p.rowid";
}
$amounts = array();
$amountsresttopay = array();
@ -79,8 +85,7 @@ $multicurrency_amounts = array();
$multicurrency_amountsresttopay = array();
// Security check
if ($user->socid > 0)
{
if ($user->socid > 0) {
$socid = $user->socid;
}
@ -103,8 +108,7 @@ $arrayfields = array();
* Actions
*/
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
{
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 = "";
@ -119,12 +123,12 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
$parameters = array('socid'=>$socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook))
{
if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes'))
{
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'));
@ -135,10 +139,8 @@ if (empty($reshook))
// 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_')
{
foreach ($_POST as $key => $value) {
if (substr($key, 0, 7) == 'amount_') {
$cursorfacid = substr($key, 7);
$amounts[$cursorfacid] = price2num(GETPOST($key));
if (!empty($amounts[$cursorfacid])) {
@ -150,19 +152,18 @@ if (empty($reshook))
}
}
$result = $tmpinvoice->fetch($cursorfacid);
if ($result <= 0) dol_print_error($db);
if ($result <= 0) {
dol_print_error($db);
}
$amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
if ($amounts[$cursorfacid])
{
if ($amounts[$cursorfacid]) {
// Check amount
if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
{
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))
{
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');
@ -170,26 +171,26 @@ if (empty($reshook))
}
$formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => $_POST[$key]);
} elseif (substr($key, 0, 21) == 'multicurrency_amount_')
{
} elseif (substr($key, 0, 21) == 'multicurrency_amount_') {
$cursorfacid = substr($key, 21);
$multicurrency_amounts[$cursorfacid] = (GETPOST($key) ? price2num(GETPOST($key)) : 0);
$multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid];
if (!empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++;
if (!empty($multicurrency_amounts[$cursorfacid])) {
$atleastonepaymentnotnull++;
}
$result = $tmpinvoice->fetch($cursorfacid);
if ($result <= 0) dol_print_error($db);
if ($result <= 0) {
dol_print_error($db);
}
$multicurrency_amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement(1));
if ($multicurrency_amounts[$cursorfacid])
{
if ($multicurrency_amounts[$cursorfacid]) {
// Check amount
if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid])))
{
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))
{
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');
@ -201,37 +202,31 @@ if (empty($reshook))
}
// Check parameters
if ($_POST['paiementid'] <= 0)
{
if ($_POST['paiementid'] <= 0) {
setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('PaymentMode')), null, 'errors');
$error++;
}
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
// If bank module is on, account is required to enter a payment
if (GETPOST('accountid') <= 0)
{
if (GETPOST('accountid') <= 0) {
setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors');
$error++;
}
}
if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull))
{
if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) {
setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->trans('PaymentAmount')), null, 'errors');
$error++;
}
if (empty($datepaye))
{
if (empty($datepaye)) {
setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('Date')), null, 'errors');
$error++;
}
// Check if payments in both currency
if ($totalpayment > 0 && $multicurrency_totalpayment > 0)
{
if ($totalpayment > 0 && $multicurrency_totalpayment > 0) {
setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors');
$error++;
}
@ -240,10 +235,8 @@ if (empty($reshook))
/*
* Action add_paiement
*/
if ($action == 'add_paiement')
{
if ($error)
{
if ($action == 'add_paiement') {
if ($error) {
$action = 'create';
}
// All the next of this action is displayed at the page's bottom.
@ -253,30 +246,25 @@ if (empty($reshook))
/*
* Action confirm_paiement
*/
if ($action == 'confirm_paiement' && $confirm == 'yes')
{
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
{
foreach ($amounts as $key => $value) { // How payment is dispatched
$tmpinvoice = new FactureFournisseur($db);
$tmpinvoice->fetch($key);
if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE)
{
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
{
foreach ($multicurrency_amounts as $key => $value) { // How payment is dispatched
$tmpinvoice = new FactureFournisseur($db);
$tmpinvoice->fetch($key);
if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE)
{
if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
$newvalue = price2num($value, 'MT');
$multicurrency_amounts[$key] = - abs($newvalue);
}
@ -286,12 +274,13 @@ if (empty($reshook))
//var_dump($multicurrency_amounts);
//exit;
if (!$error)
{
if (!$error) {
$db->begin();
$thirdparty = new Societe($db);
if ($socid > 0) $thirdparty->fetch($socid);
if ($socid > 0) {
$thirdparty->fetch($socid);
}
// Creation of payment line
$paiement = new PaiementFourn($db);
@ -305,43 +294,42 @@ if (empty($reshook))
$paiement->num_payment = $paiement->num_payment;
$paiement->note_private = $paiement->note_private;
if (!$error)
{
if (!$error) {
$paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices') == 'on' ? 1 : 0), $thirdparty);
if ($paiement_id < 0)
{
if ($paiement_id < 0) {
setEventMessages($paiement->error, $paiement->errors, 'errors');
$error++;
}
}
if (!$error)
{
if (!$error) {
$result = $paiement->addPaymentToBank($user, 'payment_supplier', '(SupplierInvoicePayment)', $accountid, '', '');
if ($result < 0)
{
if ($result < 0) {
setEventMessages($paiement->error, $paiement->errors, 'errors');
$error++;
}
}
if (!$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)
{
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 (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;
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 {
@ -364,8 +352,7 @@ $invoicesupplierstatic = new FactureFournisseur($db);
llxHeader('', $langs->trans('ListPayment'));
if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement')
{
if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement') {
$object = new FactureFournisseur($db);
$result = $object->fetch($facid);
@ -374,26 +361,29 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$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->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
if (!$user->rights->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->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= ' WHERE f.fk_soc = s.rowid';
$sql .= ' AND f.rowid = '.$facid;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
if ($num)
{
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))
{
if (!empty($conf->use_javascript_ajax)) {
print "\n".'<script type="text/javascript" language="javascript">';
print '$(document).ready(function () {
@ -491,8 +481,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print '<tr><td class="fieldrequired">'.$langs->trans('PaymentMode').'</td><td>';
$form->select_types_paiements(empty($_POST['paiementid']) ? $obj->fk_mode_reglement : $_POST['paiementid'], 'paiementid');
print '</td>';
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
print '<tr><td class="fieldrequired">'.$langs->trans('Account').'</td><td>';
$form->select_comptes(empty($accountid) ? $obj->fk_account : $accountid, 'accountid', 0, '', 2);
print '</td></tr>';
@ -510,11 +499,10 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$parameters = array('facid'=>$facid, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
$reshook = $hookmanager->executeHooks('paymentsupplierinvoices', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
$error = $hookmanager->error; $errors = $hookmanager->errors;
if (empty($reshook))
{
if (empty($reshook)) {
/*
* All unpaid supplier invoices
*/
* 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,';
@ -525,8 +513,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$sql .= ' AND f.fk_soc = '.$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)
{
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
@ -537,11 +524,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$sql .= ' ORDER BY f.datef ASC, f.ref ASC';
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
if ($num > 0)
{
if ($num > 0) {
$i = 0;
print '<br>';
@ -582,12 +567,13 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$total = 0;
$total_ttc = 0;
$totalrecu = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $db->fetch_object($resql);
$sign = 1;
if ($objp->type == FactureFournisseur::TYPE_CREDIT_NOTE) $sign = -1;
if ($objp->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
$sign = -1;
}
$invoice = new FactureFournisseur($db);
$invoice->fetch($objp->facid);
@ -629,13 +615,11 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
// Date Max Payment
if ($objp->dlr > 0)
{
if ($objp->dlr > 0) {
print '<td class="center nowraponall">';
print dol_print_date($db->jdate($objp->dlr), 'day');
if ($invoice->hasDelay())
{
if ($invoice->hasDelay()) {
print img_warning($langs->trans('Late'));
}
@ -645,28 +629,24 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
// Multicurrency
if (!empty($conf->multicurrency->enabled))
{
if (!empty($conf->multicurrency->enabled)) {
// Currency
print '<td class="center">'.$objp->multicurrency_code."</td>\n";
print '<td class="right">';
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
{
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
print price($objp->multicurrency_total_ttc);
}
print '</td>';
print '<td class="right">';
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
{
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
print price($objp->multicurrency_am);
}
print '</td>';
print '<td class="right">';
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
{
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
print price($objp->multicurrency_total_ttc - $objp->multicurrency_am);
}
print '</td>';
@ -675,8 +655,12 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print '<td class="right">'.price($sign * $objp->total_ttc).'</td>';
print '<td class="right">'.price($sign * $objp->am);
if ($creditnotes) print '+'.price($creditnotes);
if ($deposits) print '+'.price($deposits);
if ($creditnotes) {
print '+'.price($creditnotes);
}
if ($deposits) {
print '+'.price($deposits);
}
print '</td>';
print '<td class="right">'.price($sign * $remaintopay).'</td>';
@ -687,10 +671,10 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$namef = 'amount_'.$objp->facid;
$nameRemain = 'remain_'.$objp->facid;
if ($action != 'add_paiement')
{
if (!empty($conf->use_javascript_ajax))
if ($action != 'add_paiement') {
if (!empty($conf->use_javascript_ajax)) {
print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'");
}
print '<input type="hidden" class="remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
print '<input type="text" size="8" class="amount" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">'; // class is requied to be used by javascript callForResult();
} else {
@ -700,20 +684,18 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print "</td>";
// Multicurrency Price
if (!empty($conf->multicurrency->enabled))
{
if (!empty($conf->multicurrency->enabled)) {
print '<td class="right">';
// Add remind multicurrency amount
$namef = 'multicurrency_amount_'.$objp->facid;
$nameRemain = 'multicurrency_remain_'.$objp->facid;
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
{
if ($action != 'add_paiement')
{
if (!empty($conf->use_javascript_ajax))
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
if ($action != 'add_paiement') {
if (!empty($conf->use_javascript_ajax)) {
print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'");
}
print '<input type=hidden class="multicurrency_remain" name="'.$nameRemain.'" value="'.$multicurrency_remaintopay.'">';
print '<input type="text" size="8" class="multicurrency_amount" name="'.$namef.'" value="'.$_POST[$namef].'">';
} else {
@ -744,8 +726,12 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
print '<td class="right"><b>'.price($sign * $total_ttc).'</b></td>';
print '<td class="right"><b>'.price($sign * $totalrecu);
if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
if ($totalrecucreditnote) {
print '+'.price($totalrecucreditnote);
}
if ($totalrecudeposits) {
print '+'.price($totalrecudeposits);
}
print '</b></td>';
print '<td class="right"><b>'.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).'</b></td>';
print '<td class="center" id="result" style="font-weight: bold;"></td>'; // Autofilled
@ -765,25 +751,23 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
// Save Button
if ($action != 'add_paiement')
{
if ($action != 'add_paiement') {
print '<br><div class="center"><input type="checkbox" checked name="closepaidinvoices"> '.$langs->trans("ClosePaidInvoicesAutomatically");
print '<br><input type="submit" class="button" value="'.$langs->trans('ToMakePayment').'"></div>';
}
// Form to confirm payment
if ($action == 'add_paiement')
{
if ($action == 'add_paiement') {
$preselectedchoice = $addwarning ? 'no' : 'yes';
print '<br>';
if (!empty($totalpayment)) $text = $langs->trans('ConfirmSupplierPayment', price($totalpayment), $langs->trans("Currency".$conf->currency));
if (!empty($multicurrency_totalpayment))
{
if (!empty($totalpayment)) {
$text = $langs->trans('ConfirmSupplierPayment', price($totalpayment), $langs->trans("Currency".$conf->currency));
}
if (!empty($multicurrency_totalpayment)) {
$text .= '<br>'.$langs->trans('ConfirmSupplierPayment', price($multicurrency_totalpayment), $langs->trans("paymentInInvoiceCurrency"));
}
if (GETPOST('closepaidinvoices'))
{
if (GETPOST('closepaidinvoices')) {
$text .= '<br>'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
print '<input type="hidden" name="closepaidinvoices" value="'.GETPOST('closepaidinvoices').'">';
}

View File

@ -32,36 +32,39 @@ $langs->loadLangs(array('bills'));
// Security check
$socid = '';
if (!empty($user->socid)) $socid = $user->socid;
if (!empty($user->socid)) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
$action = GETPOST('action', 'aZ09');
$socid = 0;
if ($user->socid > 0)
{
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
$dir = $conf->fournisseur->facture->dir_output.'/payments';
if (!$user->rights->societe->client->voir || $socid) $dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
if (!$user->rights->societe->client->voir || $socid) {
$dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
}
$year = GETPOST("year", 'int');
if (!$year) { $year = date("Y"); }
if (!$year) {
$year = date("Y");
}
/*
* Actions
*/
if ($action == 'builddoc')
{
if ($action == 'builddoc') {
$rap = new pdf_paiement_fourn($db);
$outputlangs = $langs;
if (GETPOST('lang_id', 'aZ09'))
{
if (GETPOST('lang_id', 'aZ09')) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
}
@ -69,8 +72,7 @@ if ($action == 'builddoc')
// We save charset_output to restore it because write_file can change it if needed for
// output format that does not support UTF8.
$sav_charset_output = $outputlangs->charset_output;
if ($rap->write_file($dir, GETPOST("remonth", 'int'), GETPOST("reyear", 'int'), $outputlangs) > 0)
{
if ($rap->write_file($dir, GETPOST("remonth", 'int'), GETPOST("reyear", 'int'), $outputlangs) > 0) {
$outputlangs->charset_output = $sav_charset_output;
} else {
$outputlangs->charset_output = $sav_charset_output;
@ -114,15 +116,11 @@ clearstatcache();
// Show link on other years
$linkforyear = array();
$found = 0;
if (is_dir($dir))
{
if (is_dir($dir)) {
$handle = opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file))
{
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file)) {
$found = 1;
$linkforyear[] = $file;
}
@ -130,18 +128,17 @@ if (is_dir($dir))
}
}
asort($linkforyear);
foreach ($linkforyear as $cursoryear)
{
foreach ($linkforyear as $cursoryear) {
print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
}
if ($year)
{
if (is_dir($dir.'/'.$year))
{
if ($year) {
if (is_dir($dir.'/'.$year)) {
$handle = opendir($dir.'/'.$year);
if ($found) print '<br>';
if ($found) {
print '<br>';
}
print '<br>';
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
@ -150,12 +147,9 @@ if ($year)
print '<td class="right">'.$langs->trans("Date").'</td>';
print '</tr>';
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if (preg_match('/^supplier_payment/i', $file))
{
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (preg_match('/^supplier_payment/i', $file)) {
$tfile = $dir.'/'.$year.'/'.$file;
$relativepath = $year.'/'.$file;
print '<tr class="oddeven"><td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_fournisseur&amp;file=payments/'.urlencode($relativepath).'">'.img_pdf().' '.$file.'</a>'.$formfile->showPreview($file, 'facture_fournisseur', 'payments/'.$relativepath, 0).'</td>';

View File

@ -19,8 +19,7 @@
*/
// Protection to avoid direct call of template
if (empty($conf) || !is_object($conf))
{
if (empty($conf) || !is_object($conf)) {
print "Error, template page can't be called as URL";
exit;
}
@ -38,24 +37,26 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
$langs->load("bills");
$total = 0; $ilink = 0;
foreach ($linkedObjectBlock as $key => $objectlink)
{
foreach ($linkedObjectBlock as $key => $objectlink) {
$ilink++;
$trclass = 'oddeven';
if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass .= ' liste_sub_total';
if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) {
$trclass .= ' liste_sub_total';
}
?>
<tr class="<?php echo $trclass; ?>">
<td><?php echo $langs->trans("SupplierInvoice"); ?></td>
<td><a href="<?php echo DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$objectlink->id ?>"><?php echo img_object($langs->trans("ShowBill"), "bill").' '.$objectlink->ref; ?></a></td>
<td class="left"><?php echo $objectlink->ref_supplier; ?></td>
<td class="center"><?php echo dol_print_date($objectlink->date, 'day'); ?></td>
<td class="right"><?php
<tr class="<?php echo $trclass; ?>">
<td><?php echo $langs->trans("SupplierInvoice"); ?></td>
<td><a href="<?php echo DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$objectlink->id ?>"><?php echo img_object($langs->trans("ShowBill"), "bill").' '.$objectlink->ref; ?></a></td>
<td class="left"><?php echo $objectlink->ref_supplier; ?></td>
<td class="center"><?php echo dol_print_date($objectlink->date, 'day'); ?></td>
<td class="right"><?php
if ($user->rights->fournisseur->facture->lire) {
$sign = 1;
if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) $sign = -1;
if ($objectlink->statut != 3)
{
if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
$sign = -1;
}
if ($objectlink->statut != 3) {
// If not abandonned
$total = $total + $sign * $objectlink->total_ht;
echo price($objectlink->total_ht);
@ -63,24 +64,23 @@ foreach ($linkedObjectBlock as $key => $objectlink)
echo '<strike>'.price($objectlink->total_ht).'</strike>';
}
} ?></td>
<td class="right"><?php echo $objectlink->getLibStatut(3); ?></td>
<td class="right"><a class="reposition" href="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dellink&dellinkid='.$key; ?>"><?php echo img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink'); ?></a></td>
</tr>
<?php
<td class="right"><?php echo $objectlink->getLibStatut(3); ?></td>
<td class="right"><a class="reposition" href="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dellink&dellinkid='.$key; ?>"><?php echo img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink'); ?></a></td>
</tr>
<?php
}
if (count($linkedObjectBlock) > 1)
{
if (count($linkedObjectBlock) > 1) {
?>
<tr class="liste_total <?php echo (empty($noMoreLinkedObjectBlockAfter) ? 'liste_sub_total' : ''); ?>">
<td><?php echo $langs->trans("Total"); ?></td>
<td></td>
<td class="center"></td>
<td class="center"></td>
<td class="right"><?php echo price($total); ?></td>
<td class="right"></td>
<td class="right"></td>
</tr>
<?php
<tr class="liste_total <?php echo (empty($noMoreLinkedObjectBlockAfter) ? 'liste_sub_total' : ''); ?>">
<td><?php echo $langs->trans("Total"); ?></td>
<td></td>
<td class="center"></td>
<td class="center"></td>
<td class="right"><?php echo price($total); ?></td>
<td class="right"></td>
<td class="right"></td>
</tr>
<?php
}
print "<!-- END PHP TEMPLATE -->\n";

View File

@ -32,7 +32,9 @@ $langs->loadLangs(array("suppliers", "orders", "companies"));
// Security check
$socid = GETPOST("socid", 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'societe', $socid, '');
@ -58,15 +60,18 @@ print '<div class="fichecenter"><div class="fichethirdleft">';
$sql = "SELECT count(cf.rowid), cf.fk_statut";
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf,";
$sql .= " ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
}
$sql .= " WHERE cf.fk_soc = s.rowid ";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND sc.fk_user = ".$user->id;
}
$sql .= " AND cf.entity = ".$conf->entity;
$sql .= " GROUP BY cf.fk_statut";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -74,8 +79,7 @@ if ($resql)
print '<tr class="liste_titre"><td>'.$langs->trans("Orders").'</td><td class="center">'.$langs->trans("Nb").'</td><td>&nbsp;</td>';
print "</tr>\n";
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
print '<tr class="oddeven">';
@ -95,35 +99,37 @@ if ($resql)
// Draft orders
if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled))
{
if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) {
$langs->load("orders");
$sql = "SELECT cf.rowid, cf.ref, cf.total_ttc,";
$sql .= " s.nom as name, s.rowid as socid";
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
}
$sql .= " WHERE cf.fk_soc = s.rowid";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND sc.fk_user = ".$user->id;
}
$sql .= " AND cf.entity = ".$conf->entity;
$sql .= " AND cf.fk_statut = 0";
if ($socid) $sql .= " AND cf.fk_soc = ".$socid;
if ($socid) {
$sql .= " AND cf.fk_soc = ".$socid;
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$total = 0;
$num = $db->num_rows($resql);
if ($num)
{
if ($num) {
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("DraftOrders").'<span class="badge marginleftonlyshort">'.$num.'</span></td></tr>';
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven"><td class="nowrap">';
@ -141,8 +147,7 @@ if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUP
$i++;
$total += $obj->total_ttc;
}
if ($total > 0)
{
if ($total > 0) {
print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" class="right">'.price($total)."</td></tr>";
}
print "</table>";
@ -152,34 +157,36 @@ if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUP
}
// Draft invoices
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire)
{
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) {
$sql = "SELECT ff.ref_supplier, ff.rowid, ff.total_ttc, ff.type";
$sql .= ", s.nom as name, s.rowid as socid";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
}
$sql .= " WHERE s.rowid = ff.fk_soc";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND sc.fk_user = ".$user->id;
}
$sql .= " AND ff.entity = ".$conf->entity;
$sql .= " AND ff.fk_statut = 0";
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
if ($num)
{
if ($num) {
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("DraftBills").'<span class="badge marginleftonlyshort">'.$num.'</span></td></tr>';
$i = 0;
$tot_ttc = 0;
while ($i < $num && $i < 20)
{
while ($i < $num && $i < 20) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven"><td class="nowrap">';
@ -226,18 +233,23 @@ $sql = "SELECT s.rowid as socid, s.nom as name, s.town, s.datec, s.tms, s.prefix
$sql .= ", st.libelle as stcomm";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.fk_stcomm = st.id";
$sql .= " AND s.fournisseur = 1";
$sql .= " AND s.entity IN (".getEntity('societe').")";
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 (!$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;
}
$sql .= " ORDER BY s.tms DESC";
$sql .= $db->plimit($max, 0);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$langs->load("boxes");
$num = $db->num_rows($resql);
$i = 0;
@ -248,8 +260,7 @@ if ($resql)
print '<td class="right">'.$langs->trans("DateModification")."</td>\n";
print "</tr>\n";
while ($obj = $db->fetch_object($resql))
{
while ($obj = $db->fetch_object($resql)) {
print '<tr class="oddeven">';
print '<td><a href="card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowSupplier"), "company").'</a>';
print "&nbsp;<a href=\"card.php?socid=".$obj->socid."\">".$obj->name."</a></td>\n";
@ -271,8 +282,7 @@ if ($resql)
$companystatic->LoadSupplierCateg();
$categstatic = new Categorie($db);
if (count($companystatic->SupplierCategories))
{
if (count($companystatic->SupplierCategories)) {
print '<br>';
print '<table class="liste centpercent">';
@ -280,8 +290,7 @@ if (count($companystatic->SupplierCategories))
print $langs->trans("Category");
print "</td></tr>\n";
foreach ($companystatic->SupplierCategories as $rowid => $label)
{
foreach ($companystatic->SupplierCategories as $rowid => $label) {
print '<tr class="oddeven">'."\n";
print '<td>';
$categstatic->id = $rowid;

View File

@ -21,13 +21,27 @@
* \brief File that include javascript functions used for dispatching qty/stock/lot
*/
if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1);
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1);
if (!defined('NOLOGIN')) define('NOLOGIN', 1);
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1);
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1);
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
if (!defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
if (!defined('NOCSRFCHECK')) {
define('NOCSRFCHECK', 1);
}
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', 1);
}
if (!defined('NOLOGIN')) {
define('NOLOGIN', 1);
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', 1);
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', 1);
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
session_cache_limiter('public');
@ -36,8 +50,11 @@ require_once '../../main.inc.php';
// Define javascript type
top_httphead('text/javascript; charset=UTF-8');
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
if (empty($dolibarr_nocache)) header('Cache-Control: max-age=10800, public, must-revalidate');
else header('Cache-Control: no-cache');
if (empty($dolibarr_nocache)) {
header('Cache-Control: max-age=10800, public, must-revalidate');
} else {
header('Cache-Control: no-cache');
}
?>
/**

View File

@ -48,7 +48,9 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ
$result = restrictedArea($user, $object->element, $object->id, 'paiementfourn', '');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
// Now check also permission on thirdparty of invoices of payments. Thirdparty were loaded by the fetch_object before based on first invoice.
// It should be enough because all payments are done on invoices of the same thirdparty.
if ($socid && $socid != $object->thirdparty->id) {
@ -60,14 +62,12 @@ if ($socid && $socid != $object->thirdparty->id) {
* Actions
*/
if ($action == 'setnote' && $user->rights->fournisseur->facture->creer)
{
if ($action == 'setnote' && $user->rights->fournisseur->facture->creer) {
$db->begin();
$object->fetch($id);
$result = $object->update_note(GETPOST('note', 'restricthtml'));
if ($result > 0)
{
if ($result > 0) {
$db->commit();
$action = '';
} else {
@ -76,14 +76,12 @@ if ($action == 'setnote' && $user->rights->fournisseur->facture->creer)
}
}
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer)
{
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer) {
$db->begin();
$object->fetch($id);
$result = $object->delete();
if ($result > 0)
{
if ($result > 0) {
$db->commit();
header('Location: '.DOL_URL_ROOT.'/fourn/paiement/list.php');
exit;
@ -96,13 +94,11 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisse
if ($action == 'confirm_validate' && $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)))
)
{
) {
$db->begin();
$object->fetch($id);
if ($object->validate() >= 0)
{
if ($object->validate() >= 0) {
$db->commit();
header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
exit;
@ -112,25 +108,21 @@ if ($action == 'confirm_validate' && $confirm == 'yes' &&
}
}
if ($action == 'setnum_paiement' && !empty($_POST['num_paiement']))
{
if ($action == 'setnum_paiement' && !empty($_POST['num_paiement'])) {
$object->fetch($id);
$res = $object->update_num($_POST['num_paiement']);
if ($res === 0)
{
if ($res === 0) {
setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
} else {
setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
}
}
if ($action == 'setdatep' && !empty($_POST['datepday']))
{
if ($action == 'setdatep' && !empty($_POST['datepday'])) {
$object->fetch($id);
$datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'));
$res = $object->update_date($datepaye);
if ($res === 0)
{
if ($res === 0) {
setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
} else {
setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
@ -159,21 +151,18 @@ $head = payment_supplier_prepare_head($object);
print dol_get_fiche_head($head, 'payment', $langs->trans('SupplierPayment'), -1, 'payment');
if ($result > 0)
{
if ($result > 0) {
/*
* Confirmation of payment's delete
*/
if ($action == 'delete')
{
if ($action == 'delete') {
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete');
}
/*
* Confirmation of payment's validation
*/
if ($action == 'validate')
{
if ($action == 'validate') {
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_validate');
}
@ -189,7 +178,7 @@ if ($result > 0)
/*print '<tr>';
print '<td width="20%">'.$langs->trans('Ref').'</td><td>';
print $form->showrefnav($object,'id','',1,'rowid','ref');
print $form->showrefnav($object,'id','',1,'rowid','ref');
print '</td></tr>';*/
// Date of payment
@ -211,28 +200,24 @@ if ($result > 0)
print '<td>';
print $form->editfieldval("Numero",'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
print '</td></tr>';
*/
*/
// Amount
print '<tr><td>'.$langs->trans('Amount').'</td>';
print '<td>'.price($object->amount, '', $langs, 0, 0, -1, $conf->currency).'</td></tr>';
if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
{
if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
print '<tr><td>'.$langs->trans('Status').'</td>';
print '<td>'.$object->getLibStatut(4).'</td></tr>';
}
$allow_delete = 1;
// Bank account
if (!empty($conf->banque->enabled))
{
if ($object->fk_account)
{
if (!empty($conf->banque->enabled)) {
if ($object->fk_account) {
$bankline = new AccountLine($db);
$bankline->fetch($object->bank_line);
if ($bankline->rappro)
{
if ($bankline->rappro) {
$allow_delete = 0;
$title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
}
@ -276,8 +261,7 @@ if ($result > 0)
$sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
$sql .= ' AND pf.fk_paiementfourn = '.$object->id;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -293,12 +277,10 @@ if ($result > 0)
print '<td class="right">'.$langs->trans('Status').'</td>';
print "</tr>\n";
if ($num > 0)
{
if ($num > 0) {
$facturestatic = new FactureFournisseur($db);
while ($i < $num)
{
while ($i < $num) {
$objp = $db->fetch_object($resql);
$facturestatic->id = $objp->facid;
@ -328,8 +310,7 @@ if ($result > 0)
print '<td class="right">'.$facturestatic->LibStatut($objp->paye, $objp->status, 6, 1).'</td>';
print "</tr>\n";
if ($objp->paye == 1)
{
if ($objp->paye == 1) {
$allow_delete = 0;
$title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
}
@ -353,23 +334,17 @@ if ($result > 0)
*/
print '<div class="tabsAction">';
if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
{
if ($user->socid == 0 && $object->statut == 0 && $action == '')
{
if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
if ($user->socid == 0 && $object->statut == 0 && $action == '') {
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)))
{
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate))) {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Valid').'</a>';
}
}
}
if ($user->socid == 0 && $action == '')
{
if ($user->rights->fournisseur->facture->supprimer)
{
if ($allow_delete)
{
if ($user->socid == 0 && $action == '') {
if ($user->rights->fournisseur->facture->supprimer) {
if ($allow_delete) {
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans('Delete').'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$title_button.'">'.$langs->trans('Delete').'</a>';
@ -385,8 +360,7 @@ if ($result > 0)
include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
$modellist = ModelePDFSuppliersPayments::liste_modeles($db);
if (is_array($modellist))
{
if (is_array($modellist)) {
$ref = dol_sanitizeFileName($object->ref);
$filedir = $conf->fournisseur->payment->dir_output.'/'.dol_sanitizeFileName($object->ref);
$urlsource = $_SERVER['PHP_SELF'].'?id='.$object->id;

View File

@ -40,7 +40,9 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ
$result = restrictedArea($user, $object->element, $object->id, 'paiementfourn', '');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
// Now check also permission on thirdparty of invoices of payments. Thirdparty were loaded by the fetch_object before based on first invoice.
// It should be enough because all payments are done on invoices of the same thirdparty.
if ($socid && $socid != $object->thirdparty->id) {

View File

@ -35,7 +35,9 @@
require '../../main.inc.php';
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
// doesn't work :-(
// restrictedArea($user, 'fournisseur');
@ -78,13 +80,19 @@ $sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST('page', 'int');
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
}
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "p.datep";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "p.datep";
}
$search_all = trim(GETPOSTISSET("search_all") ? GETPOST("search_all", 'alpha') : GETPOST('sall'));
@ -117,7 +125,9 @@ $object = new PaiementFourn($db);
$parameters = array('socid'=>$socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) {
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
@ -150,7 +160,9 @@ $sql = 'SELECT p.rowid, p.ref, p.datep, p.amount as pamount, p.num_paiement';
$sql .= ', s.rowid as socid, s.nom as name, s.email';
$sql .= ', c.code as paiement_type, c.libelle as paiement_libelle';
$sql .= ', ba.rowid as bid, ba.label';
if (!$user->rights->societe->client->voir) $sql .= ', sc.fk_soc, sc.fk_user';
if (!$user->rights->societe->client->voir) {
$sql .= ', sc.fk_soc, sc.fk_user';
}
$sql .= ', SUM(pf.amount)';
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p';
@ -160,26 +172,48 @@ $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.rowid = f.fk_soc';
$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';
if (!$user->rights->societe->client->voir) $sql .= ', '.MAIN_DB_PREFIX.'societe_commerciaux as sc';
if (!$user->rights->societe->client->voir) {
$sql .= ', '.MAIN_DB_PREFIX.'societe_commerciaux as sc';
}
$sql .= ' WHERE f.entity = '.$conf->entity;
if (!$user->rights->societe->client->voir) $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = '.$user->id;
if ($socid > 0) $sql .= ' AND f.fk_soc = '.$socid;
if ($search_ref) $sql .= natural_search('p.ref', $search_ref);
if (!$user->rights->societe->client->voir) {
$sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = '.$user->id;
}
if ($socid > 0) {
$sql .= ' AND f.fk_soc = '.$socid;
}
if ($search_ref) {
$sql .= natural_search('p.ref', $search_ref);
}
$sql .= dolSqlDateFilter('p.datep', $search_day, $search_month, $search_year);
if ($search_company) $sql .= natural_search('s.nom', $search_company);
if ($search_payment_type != '') $sql .= " AND c.code='".$db->escape($search_payment_type)."'";
if ($search_cheque_num != '') $sql .= natural_search('p.num_paiement', $search_cheque_num);
if ($search_amount) $sql .= natural_search('p.amount', $search_amount, 1);
if ($search_bank_account > 0) $sql .= ' AND b.fk_account='.$search_bank_account."'";
if ($search_company) {
$sql .= natural_search('s.nom', $search_company);
}
if ($search_payment_type != '') {
$sql .= " AND c.code='".$db->escape($search_payment_type)."'";
}
if ($search_cheque_num != '') {
$sql .= natural_search('p.num_paiement', $search_cheque_num);
}
if ($search_amount) {
$sql .= natural_search('p.amount', $search_amount, 1);
}
if ($search_bank_account > 0) {
$sql .= ' AND b.fk_account='.$search_bank_account."'";
}
if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
if ($search_all) {
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
}
// Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
$sql .= ' GROUP BY p.rowid, p.ref, p.datep, p.amount, p.num_paiement, s.rowid, s.nom, s.email, c.code, c.libelle, ba.rowid, ba.label';
if (!$user->rights->societe->client->voir) $sql .= ', sc.fk_soc, sc.fk_user';
if (!$user->rights->societe->client->voir) {
$sql .= ', sc.fk_soc, sc.fk_user';
}
$sql .= $db->order($sortfield, $sortorder);
@ -207,24 +241,48 @@ $num = $db->num_rows($resql);
$i = 0;
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER['PHP_SELF']) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
if (!empty($contextpage) && $contextpage != $_SERVER['PHP_SELF']) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
if ($saerch_day) $param .= '&search_day='.urlencode($search_day);
if ($saerch_month) $param .= '&search_month='.urlencode($search_month);
if ($search_year) $param .= '&search_year='.urlencode($search_year);
if ($search_company) $param .= '&search_company='.urlencode($search_company);
if ($search_payment_type) $param .= '&search_company='.urlencode($search_payment_type);
if ($search_cheque_num) $param .= '&search_cheque_num='.urlencode($search_cheque_num);
if ($search_amount) $param .= '&search_amount='.urlencode($search_amount);
if ($search_ref) {
$param .= '&search_ref='.urlencode($search_ref);
}
if ($saerch_day) {
$param .= '&search_day='.urlencode($search_day);
}
if ($saerch_month) {
$param .= '&search_month='.urlencode($search_month);
}
if ($search_year) {
$param .= '&search_year='.urlencode($search_year);
}
if ($search_company) {
$param .= '&search_company='.urlencode($search_company);
}
if ($search_payment_type) {
$param .= '&search_company='.urlencode($search_payment_type);
}
if ($search_cheque_num) {
$param .= '&search_cheque_num='.urlencode($search_cheque_num);
}
if ($search_amount) {
$param .= '&search_amount='.urlencode($search_amount);
}
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
@ -234,9 +292,10 @@ print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
print_barre_liste($langs->trans('SupplierPayments'), $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'supplier_invoice', 0, '', '', $limit, 0, 0, 1);
if ($search_all)
{
foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
if ($search_all) {
foreach ($fieldstosearchall as $key => $val) {
$fieldstosearchall[$key] = $langs->trans($val);
}
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
}
@ -244,8 +303,11 @@ $moreforfilter = '';
$parameters = array();
$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 (empty($reshook)) {
$moreforfilter .= $hookmanager->resPrint;
} else {
$moreforfilter = $hookmanager->resPrint;
}
if ($moreforfilter) {
print '<div class="liste_titre liste_titre_bydiv centpercent">';
@ -255,7 +317,9 @@ if ($moreforfilter) {
$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);
if ($massactionbutton) {
$selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
}
print '<div class="div-table-responsive">';
print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : '').'">';
@ -272,7 +336,9 @@ if (!empty($arrayfields['p.ref']['checked'])) {
// Filter: Date
if (!empty($arrayfields['p.datep']['checked'])) {
print '<td class="liste_titre center">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="search_day" value="'.dol_escape_htmltag($search_day).'">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="search_day" value="'.dol_escape_htmltag($search_day).'">';
}
print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="search_month" value="'.dol_escape_htmltag($search_month).'">';
$formother->select_year($search_year ? $search_year : -1, 'search_year', 1, 20, 5);
print '</td>';
@ -326,14 +392,30 @@ print '</td>';
print '</tr>';
print '<tr class="liste_titre">';
if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.rowid', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['p.datep']['checked'])) print_liste_field_titre($arrayfields['p.datep']['label'], $_SERVER["PHP_SELF"], 'p.datep', '', $param, '', $sortfield, $sortorder, 'center ');
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['c.libelle']['checked'])) print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], 'c.libelle', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['p.num_paiement']['checked'])) print_liste_field_titre($arrayfields['p.num_paiement']['label'], $_SERVER["PHP_SELF"], "p.num_paiement", '', $param, '', $sortfield, $sortorder, '', $arrayfields['p.num_paiement']['tooltip']);
if (!empty($arrayfields['ba.label']['checked'])) print_liste_field_titre($arrayfields['ba.label']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['p.amount']['checked'])) print_liste_field_titre($arrayfields['p.amount']['label'], $_SERVER["PHP_SELF"], 'p.amount', '', $param, '', $sortfield, $sortorder, 'right ');
if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['p.ref']['checked'])) {
print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.rowid', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['p.datep']['checked'])) {
print_liste_field_titre($arrayfields['p.datep']['label'], $_SERVER["PHP_SELF"], 'p.datep', '', $param, '', $sortfield, $sortorder, 'center ');
}
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['c.libelle']['checked'])) {
print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], 'c.libelle', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['p.num_paiement']['checked'])) {
print_liste_field_titre($arrayfields['p.num_paiement']['label'], $_SERVER["PHP_SELF"], "p.num_paiement", '', $param, '', $sortfield, $sortorder, '', $arrayfields['p.num_paiement']['tooltip']);
}
if (!empty($arrayfields['ba.label']['checked'])) {
print_liste_field_titre($arrayfields['ba.label']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['p.amount']['checked'])) {
print_liste_field_titre($arrayfields['p.amount']['label'], $_SERVER["PHP_SELF"], 'p.amount', '', $param, '', $sortfield, $sortorder, 'right ');
}
// Hook fields
$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
@ -368,21 +450,29 @@ while ($i < min($num, $limit)) {
// No
if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
print '<td>'.(($offset * $limit) + $i).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Ref
if (!empty($arrayfields['p.ref']['checked'])) {
print '<td class="nowrap">'.$paymentfournstatic->getNomUrl(1).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date
if (!empty($arrayfields['p.datep']['checked'])) {
$dateformatforpayment = 'day';
if (!empty($conf->global->INVOICE_USE_HOURS_FOR_PAYMENT)) $dateformatforpayment = 'dayhour';
if (!empty($conf->global->INVOICE_USE_HOURS_FOR_PAYMENT)) {
$dateformatforpayment = 'dayhour';
}
print '<td class="nowrap center">'.dol_print_date($db->jdate($objp->datep), $dateformatforpayment).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Thirdparty
@ -392,43 +482,57 @@ while ($i < min($num, $limit)) {
print $companystatic->getNomUrl(1, '', 24);
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Pyament type
if (!empty($arrayfields['c.libelle']['checked'])) {
$payment_type = $langs->trans("PaymentType".$objp->paiement_type) != ("PaymentType".$objp->paiement_type) ? $langs->trans("PaymentType".$objp->paiement_type) : $objp->paiement_libelle;
print '<td>'.$payment_type.' '.dol_trunc($objp->num_paiement, 32).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Cheque number (fund transfer)
if (!empty($arrayfields['p.num_paiement']['checked'])) {
print '<td>'.$objp->num_paiement.'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Account
if (!empty($arrayfields['ba.label']['checked']))
{
if (!empty($arrayfields['ba.label']['checked'])) {
print '<td>';
if ($objp->bid) print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"), 'account').' '.dol_trunc($objp->label, 24).'</a>';
else print '&nbsp;';
if ($objp->bid) {
print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"), 'account').' '.dol_trunc($objp->label, 24).'</a>';
} else {
print '&nbsp;';
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Amount
if (!empty($arrayfields['p.amount']['checked'])) {
print '<td class="right">'.price($objp->pamount).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
$totalarray['pos'][$checkedCount] = 'amount';
$totalarray['val']['amount'] += $objp->pamount;
}
// Buttons
print '<td></td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
print '</tr>';
$i++;

View File

@ -33,7 +33,9 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
$langs->loadLangs(array("products", "suppliers"));
if (!$user->rights->produit->lire && !$user->rights->service->lire) accessforbidden();
if (!$user->rights->produit->lire && !$user->rights->service->lire) {
accessforbidden();
}
$sref = GETPOST('sref', 'alphanohtml');
$sRefSupplier = GETPOST('srefsupplier');
@ -46,15 +48,23 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
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
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortfield) $sortfield = "p.ref"; // Set here default search field
if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) {
$sortfield = "p.ref"; // Set here default search field
}
if (!$sortorder) {
$sortorder = "ASC";
}
$fourn_id = GETPOST('fourn_id', 'intcomma');
if ($user->socid) $fourn_id = $user->socid;
if ($user->socid) {
$fourn_id = $user->socid;
}
$catid = GETPOST('catid', 'intcomma');
@ -71,22 +81,26 @@ $extrafields = new ExtraFields($db);
* Put here all code to do according to value of "action" parameter
*/
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
if (GETPOST('cancel', 'alpha')) {
$action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook))
{
if (empty($reshook)) {
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria
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
{
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
$sref = '';
$sRefSupplier = '';
$snom = '';
@ -109,8 +123,7 @@ $companystatic = new Societe($db);
$title = $langs->trans("ProductsAndServices");
if ($fourn_id)
{
if ($fourn_id) {
$supplier = new Fournisseur($db);
$supplier->fetch($fourn_id);
}
@ -122,8 +135,12 @@ $arrayofmassactions = array(
'builddoc'=>$langs->trans("PDFMerge"),
'presend'=>$langs->trans("SendByMail"),
);
if ($user->rights->mymodule->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
if ($user->rights->mymodule->supprimer) {
$arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
}
if (in_array($massaction, array('presend', 'predelete'))) {
$arrayofmassactions = array();
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
@ -133,54 +150,52 @@ $sql .= " s.rowid as socid, s.nom as name";
// Add fields to SELECT from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$sql .= $hookmanager->resPrint;
$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
if ($catid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
if ($catid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
}
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON p.rowid = ppf.fk_product";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ppf.fk_soc = s.rowid";
$sql .= " WHERE p.entity IN (".getEntity('product').")";
if ($sRefSupplier)
{
if ($sRefSupplier) {
$sql .= natural_search('ppf.ref_fourn', $sRefSupplier);
}
if (GETPOST('type'))
{
if (GETPOST('type')) {
$sql .= " AND p.fk_product_type = ".GETPOST('type', 'int');
}
if ($sref)
{
if ($sref) {
$sql .= natural_search('p.ref', $sref);
}
if ($snom)
{
if ($snom) {
$sql .= natural_search('p.label', $snom);
}
if ($catid)
{
if ($catid) {
$sql .= " AND cp.fk_categorie = ".$catid;
}
if ($fourn_id > 0)
{
if ($fourn_id > 0) {
$sql .= " AND ppf.fk_soc = ".$fourn_id;
}
// Add WHERE filters from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$sql .= $hookmanager->resPrint;
$sql .= $db->order($sortfield, $sortorder);
// Count total nb of records without orderby and limit
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
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
{
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@ -190,30 +205,32 @@ $sql .= $db->plimit($limit + 1, $offset);
dol_syslog("fourn/product/list.php:", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
if ($num == 1 && (GETPOST("mode") == 'search'))
{
if ($num == 1 && (GETPOST("mode") == 'search')) {
$objp = $db->fetch_object($resql);
header("Location: ".DOL_URL_ROOT."/product/card.php?id=".$objp->rowid);
exit;
}
if (!empty($supplier->id)) $texte = $langs->trans("ListOfSupplierProductForSupplier", $supplier->name);
else $texte = $langs->trans("List");
if (!empty($supplier->id)) {
$texte = $langs->trans("ListOfSupplierProductForSupplier", $supplier->name);
} else {
$texte = $langs->trans("List");
}
llxHeader("", "", $texte);
$param = "&sref=".$sref."&snom=".$snom."&fourn_id=".$fourn_id.(isset($type) ? "&amp;type=".$type : "").(empty($sRefSupplier) ? "" : "&amp;srefsupplier=".$sRefSupplier);
if ($optioncss != '') $param .= '&optioncss='.$optioncss;
if ($optioncss != '') {
$param .= '&optioncss='.$optioncss;
}
print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords);
if (!empty($catid))
{
if (!empty($catid)) {
print "<div id='ways'>";
$c = new Categorie($db);
$ways = $c->print_all_ways(' &gt; ', 'fourn/product/list.php');
@ -222,9 +239,13 @@ if ($resql)
}
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
if ($fourn_id > 0) print '<input type="hidden" name="fourn_id" value="'.$fourn_id.'">';
if ($fourn_id > 0) {
print '<input type="hidden" name="fourn_id" value="'.$fourn_id.'">';
}
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">';
@ -256,7 +277,9 @@ if ($resql)
// add filters from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
print $hookmanager->resPrint;
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterButtons();
@ -276,13 +299,14 @@ if ($resql)
// add header cells from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
print $hookmanager->resPrint;
print_liste_field_titre('', $_SERVER["PHP_SELF"]);
print "</tr>\n";
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$objp = $db->fetch_object($resql);
$productstatic->id = $objp->rowid;
@ -307,7 +331,9 @@ if ($resql)
$companystatic->name = $objp->name;
$companystatic->id = $objp->socid;
print '<td>';
if ($companystatic->id > 0) print $companystatic->getNomUrl(1, 'supplier');
if ($companystatic->id > 0) {
print $companystatic->getNomUrl(1, 'supplier');
}
print '</td>';
print '<td class="right">'.(isset($objp->price) ? price($objp->price) : '').'</td>';
@ -319,7 +345,9 @@ if ($resql)
// add additional columns from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objp, $action);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
print $hookmanager->resPrint;
print '<td class="right"></td>';

View File

@ -32,8 +32,7 @@ $langs->loadLangs(array('bills', 'companies'));
// Security check
$socid = GETPOST("socid", 'int');
if ($user->socid > 0)
{
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
@ -51,22 +50,20 @@ $userstatic = new User($db);
llxHeader();
if ($socid > 0)
{
if ($socid > 0) {
$societe = new Societe($db);
$societe->fetch($socid);
/*
* Affichage onglets
*/
* Affichage onglets
*/
$head = societe_prepare_head($societe);
print dol_get_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), 0, 'company');
dol_banner_tab($societe, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
print dol_get_fiche_end();
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->facture->lire)
{
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->facture->lire) {
// Invoice list
print load_fiche_titre($langs->trans("SupplierPreview"));
@ -82,8 +79,7 @@ if ($socid > 0)
$sql .= " ORDER BY f.datef DESC";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
print '<tr class="liste_titre">';
@ -96,22 +92,19 @@ if ($socid > 0)
print '<td>&nbsp;</td>';
print '</tr>';
if (!$num > 0)
{
if (!$num > 0) {
print '<tr><td colspan="7">'.$langs->trans("NoInvoice").'</td></tr>';
}
$solde = 0;
// Boucle sur chaque facture
for ($i = 0; $i < $num; $i++)
{
for ($i = 0; $i < $num; $i++) {
$objf = $db->fetch_object($resql);
$fac = new FactureFournisseur($db);
$ret = $fac->fetch($objf->facid);
if ($ret < 0)
{
if ($ret < 0) {
print $fac->error."<br>";
continue;
}
@ -144,13 +137,11 @@ if ($socid > 0)
$sql .= " AND pf.fk_facturefourn = ".$fac->id;
$resqlp = $db->query($sql);
if ($resqlp)
{
if ($resqlp) {
$nump = $db->num_rows($resqlp);
$j = 0;
while ($j < $nump)
{
while ($j < $nump) {
$objp = $db->fetch_object($resqlp);
//
print '<tr class="oddeven">';