'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '
';
print '';
@@ -120,8 +141,7 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON ptva.fk_typepaiement = pct.id";
$sql .= " WHERE ptva.fk_tva = tva.rowid";
$sql .= " AND tva.entity = ".$conf->entity;
- if ($year > 0)
- {
+ if ($year > 0) {
$sql .= " AND (";
// Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
// ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
@@ -133,22 +153,22 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
|| preg_match('/^tva\./', $sortfield)
|| preg_match('/^ptva\./', $sortfield)
|| preg_match('/^pct\./', $sortfield)
- || preg_match('/^bank\./', $sortfield)) $sql .= $db->order($sortfield, $sortorder);
+ || preg_match('/^bank\./', $sortfield)) {
+ $sql .= $db->order($sortfield, $sortorder);
+ }
//$sql.= $db->plimit($limit+1,$offset);
//print $sql;
dol_syslog("compta/tva/payments.php: select payment", LOG_DEBUG);
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$total = 0;
$totalnb = 0;
$totalpaye = 0;
- while ($i < min($num, $limit))
- {
+ while ($i < min($num, $limit)) {
$obj = $db->fetch_object($resql);
$payment_vat_static->id = $obj->pid;
@@ -159,11 +179,13 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
print ''.$payment_vat_static->getNomUrl(1)." \n";
// Date payment
print ''.dol_print_date($db->jdate($obj->datep), 'day').' ';
- // Type payment
- print '';
- if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
- print $obj->num_payment.' ';
- // Account
+ // Type payment
+ print '';
+ if ($obj->payment_code) {
+ print $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
+ }
+ print $obj->num_payment.' ';
+ // Account
print '';
$account = new Account($db);
$account->fetch($obj->fk_account);
@@ -185,7 +207,9 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
print ' '.price($obj->total).' ';
// Paid
print '';
- if ($obj->totalpaye) print price($obj->totalpaye);
+ if ($obj->totalpaye) {
+ print price($obj->totalpaye);
+ }
print ' ';
print ' ';
@@ -194,16 +218,15 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
$totalpaye = $totalpaye + $obj->totalpaye;
$i++;
}
- print ''.$langs->trans("Total").' ';
- print ' '; // A total here has no sense
- //print ' ';
- print ' ';
+ print ''.$langs->trans("Total").' ';
+ print ' '; // A total here has no sense
+ //print ' ';
print ' ';
print ' ';
- print ''.price($totalpaye)." ";
+ print ' ';
+ print ''.price($totalpaye)." ";
print " ";
- }
- else {
+ } else {
dol_print_error($db);
}
print '
';
diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php
index ba12b08b3b0..04f90ba02f9 100644
--- a/htdocs/compta/tva/quadri_detail.php
+++ b/htdocs/compta/tva/quadri_detail.php
@@ -46,12 +46,13 @@ $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "produ
$now = dol_now();
$current_date = dol_getdate($now);
-if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) $conf->global->SOCIETE_FISCAL_MONTH_START = 1;
+if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) {
+ $conf->global->SOCIETE_FISCAL_MONTH_START = 1;
+}
// Date range
$year = GETPOST("year", "int");
-if (empty($year))
-{
+if (empty($year)) {
$year_current = $current_date['year'];
$year_start = $year_current;
} else {
@@ -61,12 +62,12 @@ if (empty($year))
$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
// Set default period if not defined
-if (empty($date_start) || empty($date_end)) // We define date_start and date_end
-{
+if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
$q = GETPOST("q", "int");
- if (empty($q))
- {
- if (GETPOST("month", "int")) { $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); } else {
+ if (empty($q)) {
+ if (GETPOST("month", "int")) {
+ $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false);
+ } else {
if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) { // quaterly vat, we take last past complete quarter
$date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -3 - (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3), 'm');
$date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
@@ -88,25 +89,41 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end
}
}
} else {
- if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
- if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); }
- if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); }
- if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
+ if ($q == 1) {
+ $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false);
+ }
+ if ($q == 2) {
+ $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false);
+ }
+ if ($q == 3) {
+ $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false);
+ }
+ if ($q == 4) {
+ $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false);
+ }
}
}
$min = price2num(GETPOST("min", "alpha"));
-if (empty($min)) $min = 0;
+if (empty($min)) {
+ $min = 0;
+}
// Define modetax (0 or 1)
// 0=normal, 1=option vat for services is on debit, 2=option on payments for products
$modetax = $conf->global->TAX_MODE;
-if (GETPOSTISSET("modetax")) $modetax = GETPOST("modetax", 'int');
-if (empty($modetax)) $modetax = 0;
+if (GETPOSTISSET("modetax")) {
+ $modetax = GETPOST("modetax", 'int');
+}
+if (empty($modetax)) {
+ $modetax = 0;
+}
// Security check
$socid = GETPOST('socid', 'int');
-if ($user->socid) $socid = $user->socid;
+if ($user->socid) {
+ $socid = $user->socid;
+}
$result = restrictedArea($user, 'tax', '', '', 'charges');
@@ -127,9 +144,10 @@ $paymentexpensereport_static = new PaymentExpenseReport($db);
$morequerystring = '';
$listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
-foreach ($listofparams as $param)
-{
- if (GETPOST($param) != '') $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
+foreach ($listofparams as $param) {
+ if (GETPOST($param) != '') {
+ $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
+ }
}
$title = $langs->trans("VATReport")." ".dol_print_date($date_start)." -> ".dol_print_date($date_end);
@@ -149,9 +167,15 @@ $fsearch .= '
';
// Show report header
$name = $langs->trans("VATReportByRates");
$calcmode = '';
-if ($modetax == 0) $calcmode = $langs->trans('OptionVATDefault');
-if ($modetax == 1) $calcmode = $langs->trans('OptionVATDebitOption');
-if ($modetax == 2) $calcmode = $langs->trans('OptionPaymentForProductAndServices');
+if ($modetax == 0) {
+ $calcmode = $langs->trans('OptionVATDefault');
+}
+if ($modetax == 1) {
+ $calcmode = $langs->trans('OptionVATDebitOption');
+}
+if ($modetax == 2) {
+ $calcmode = $langs->trans('OptionPaymentForProductAndServices');
+}
$calcmode .= '
('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').') ';
// Set period
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
@@ -173,14 +197,24 @@ if ($nextquarter < 4) {
$description .= $fsearch;
$builddate = dol_now();
-if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') $description .= $langs->trans("RulesVATDueProducts");
-if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') $description .= $langs->trans("RulesVATInProducts");
-if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') $description .= '
'.$langs->trans("RulesVATDueServices");
-if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') $description .= '
'.$langs->trans("RulesVATInServices");
+if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') {
+ $description .= $langs->trans("RulesVATDueProducts");
+}
+if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') {
+ $description .= $langs->trans("RulesVATInProducts");
+}
+if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') {
+ $description .= '
'.$langs->trans("RulesVATDueServices");
+}
+if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') {
+ $description .= '
'.$langs->trans("RulesVATInServices");
+}
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$description .= '
'.$langs->trans("DepositsAreNotIncluded");
}
-if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description .= '
'.$langs->trans("ThisIsAnEstimatedValue");
+if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
+ $description .= '
'.$langs->trans("ThisIsAnEstimatedValue");
+}
// Customers invoices
$elementcust = $langs->trans("CustomersInvoices");
@@ -225,8 +259,7 @@ $columns = 5;
$x_coll = tax_by_rate('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
$x_paye = tax_by_rate('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
-if (!is_array($x_coll) || !is_array($x_paye))
-{
+if (!is_array($x_coll) || !is_array($x_paye)) {
$langs->load("errors");
if ($x_coll == -1) {
print '
'.$langs->trans("ErrorNoAccountancyModuleLoaded").' ';
@@ -238,15 +271,14 @@ if (!is_array($x_coll) || !is_array($x_paye))
} else {
$x_both = array();
//now, from these two arrays, get another array with one rate per line
- foreach (array_keys($x_coll) as $my_coll_rate)
- {
+ foreach (array_keys($x_coll) as $my_coll_rate) {
$x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
$x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
$x_both[$my_coll_rate]['paye']['totalht'] = 0;
$x_both[$my_coll_rate]['paye']['vat'] = 0;
$x_both[$my_coll_rate]['coll']['links'] = '';
$x_both[$my_coll_rate]['coll']['detail'] = array();
- foreach ($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) {
+ foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) {
$invoice_customer->id = $x_coll[$my_coll_rate]['facid'][$id];
$invoice_customer->ref = $x_coll[$my_coll_rate]['facnum'][$id];
$invoice_customer->type = $x_coll[$my_coll_rate]['type'][$id];
@@ -284,11 +316,9 @@ if (!is_array($x_coll) || !is_array($x_paye))
$x_both[$my_paye_rate]['paye']['links'] = '';
$x_both[$my_paye_rate]['paye']['detail'] = array();
- foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
- {
+ foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
// ExpenseReport
- if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment')
- {
+ if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') {
$expensereport->id = $x_paye[$my_paye_rate]['facid'][$id];
$expensereport->ref = $x_paye[$my_paye_rate]['facnum'][$id];
$expensereport->type = $x_paye[$my_paye_rate]['type'][$id];
@@ -349,7 +379,9 @@ if (!is_array($x_coll) || !is_array($x_paye))
$x_paye_ht = 0;
$span = $columns;
- if ($modetax != 1) $span += 2;
+ if ($modetax != 1) {
+ $span += 2;
+ }
//print '
'..') ';
@@ -357,12 +389,14 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '
';
print ''.$elementcust.' ';
print ''.$langs->trans("DateInvoice").' ';
- if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print ''.$langs->trans("DatePayment").' ';
- else print ' ';
+ if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') {
+ print ''.$langs->trans("DatePayment").' ';
+ } else {
+ print ' ';
+ }
print ''.$namecust.' ';
print ''.$productcust.' ';
- if ($modetax != 1)
- {
+ if ($modetax != 1) {
print ''.$amountcust.' ';
print ''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").') ';
}
@@ -385,8 +419,7 @@ if (!is_array($x_coll) || !is_array($x_paye))
$subtot_coll_total_ht = 0;
$subtot_coll_vat = 0;
- if (is_array($x_both[$rate]['coll']['detail']))
- {
+ if (is_array($x_both[$rate]['coll']['detail'])) {
// VAT Rate
print " ";
print ''.$langs->trans("Rate").': '.vatrate($rate).'% ';
@@ -415,16 +448,18 @@ if (!is_array($x_coll) || !is_array($x_paye))
print ''.dol_print_date($fields['datef'], 'day').' ';
// Payment date
- if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print ''.dol_print_date($fields['datep'], 'day').' ';
- else print ' ';
+ if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') {
+ print ''.dol_print_date($fields['datep'], 'day').' ';
+ } else {
+ print ' ';
+ }
// Company name
print ''.$fields['company_link'].' ';
// Description
print '';
- if ($fields['pid'])
- {
+ if ($fields['pid']) {
$product_static->id = $fields['pid'];
$product_static->ref = $fields['pref'];
$product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
@@ -455,12 +490,10 @@ if (!is_array($x_coll) || !is_array($x_paye))
print ' ';
// Total HT
- if ($modetax != 1)
- {
+ if ($modetax != 1) {
print '';
print price($fields['totalht']);
- if (price2num($fields['ftotal_ttc']))
- {
+ if (price2num($fields['ftotal_ttc'])) {
//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
$ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
//print ' ('.round($ratiolineinvoice*100,2).'%)';
@@ -470,18 +503,15 @@ if (!is_array($x_coll) || !is_array($x_paye))
// Payment
$ratiopaymentinvoice = 1;
- if ($modetax != 1)
- {
+ if ($modetax != 1) {
print ' ';
//print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
- if ($fields['payment_amount'] && $fields['ftotal_ttc'])
- {
+ if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
$payment_static->id = $fields['payment_id'];
print $payment_static->getNomUrl(2);
}
if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
- || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
- {
+ || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
print $langs->trans("NA");
} else {
if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
@@ -527,8 +557,7 @@ if (!is_array($x_coll) || !is_array($x_paye))
print ' ';
}
- if (count($x_coll) == 0) // Show a total line if nothing shown
- {
+ if (count($x_coll) == 0) { // Show a total line if nothing shown
print '
';
print ' ';
print ''.$langs->trans("Total").': ';
@@ -548,8 +577,11 @@ if (!is_array($x_coll) || !is_array($x_paye))
print ' ';
print ''.$elementsup.' ';
print ''.$langs->trans("DateInvoice").' ';
- if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print ''.$langs->trans("DatePayment").' ';
- else print ' ';
+ if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') {
+ print ''.$langs->trans("DatePayment").' ';
+ } else {
+ print ' ';
+ }
print ''.$namesup.' ';
print ''.$productsup.' ';
if ($modetax != 1) {
@@ -560,18 +592,16 @@ if (!is_array($x_coll) || !is_array($x_paye))
print ''.$vatsup.' ';
print ' '."\n";
- foreach (array_keys($x_paye) as $rate)
- {
+ foreach (array_keys($x_paye) as $rate) {
$subtot_paye_total_ht = 0;
$subtot_paye_vat = 0;
- if (is_array($x_both[$rate]['paye']['detail']))
- {
+ if (is_array($x_both[$rate]['paye']['detail'])) {
print "
";
print ''.$langs->trans("Rate").': '.vatrate($rate).'% ';
print ' '."\n";
- foreach ($x_both[$rate]['paye']['detail'] as $index=>$fields) {
+ foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
// Define type
// We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
$type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
@@ -594,16 +624,18 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '
'.dol_print_date($fields['datef'], 'day').' ';
// Payment date
- if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '
'.dol_print_date($fields['datep'], 'day').' ';
- else print '
';
+ if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') {
+ print '
'.dol_print_date($fields['datep'], 'day').' ';
+ } else {
+ print '
';
+ }
// Company name
print '
'.$fields['company_link'].' ';
// Description
print '
';
- if ($fields['pid'])
- {
+ if ($fields['pid']) {
$product_static->id = $fields['pid'];
$product_static->ref = $fields['pref'];
$product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered
@@ -634,12 +666,10 @@ if (!is_array($x_coll) || !is_array($x_paye))
print ' ';
// Total HT
- if ($modetax != 1)
- {
+ if ($modetax != 1) {
print '
';
print price($fields['totalht']);
- if (price2num($fields['ftotal_ttc']))
- {
+ if (price2num($fields['ftotal_ttc'])) {
//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
$ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
//print ' ('.round($ratiolineinvoice*100,2).'%)';
@@ -649,18 +679,15 @@ if (!is_array($x_coll) || !is_array($x_paye))
// Payment
$ratiopaymentinvoice = 1;
- if ($modetax != 1)
- {
+ if ($modetax != 1) {
print ' ';
- if ($fields['payment_amount'] && $fields['ftotal_ttc'])
- {
+ if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
$paymentfourn_static->id = $fields['payment_id'];
print $paymentfourn_static->getNomUrl(2);
}
if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')
- || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice'))
- {
+ || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) {
print $langs->trans("NA");
} else {
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
diff --git a/htdocs/contact/agenda.php b/htdocs/contact/agenda.php
index 2aeb2e4e2a1..ca496540a47 100644
--- a/htdocs/contact/agenda.php
+++ b/htdocs/contact/agenda.php
@@ -65,36 +65,44 @@ $extrafields->fetch_name_optionals_label($object->table_element);
$object->getCanvas($id);
$objcanvas = null;
$canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
-if (!empty($canvas))
-{
+if (!empty($canvas)) {
require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
$objcanvas = new Canvas($db, $action);
$objcanvas->getCanvas('contact', 'contactcard', $canvas);
}
-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_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
}
$search_agenda_label = GETPOST('search_agenda_label');
// Security check
-if ($user->socid) $socid = $user->socid;
+if ($user->socid) {
+ $socid = $user->socid;
+}
$result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
$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 (!$sortfield) $sortfield = 'a.datep, a.id';
-if (!$sortorder) $sortorder = 'DESC';
+if (!$sortfield) {
+ $sortfield = 'a.datep, a.id';
+}
+if (!$sortorder) {
+ $sortorder = 'DESC';
+}
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('contactagenda', 'globalcard'));
@@ -106,20 +114,19 @@ $hookmanager->initHooks(array('contactagenda', 'globalcard'));
$parameters = array('id'=>$id, 'objcanvas'=>$objcanvas);
$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)) {
// Cancel
- if (GETPOST('cancel', 'alpha') && !empty($backtopage))
- {
+ if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
header("Location: ".$backtopage);
exit;
}
// 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 = '';
}
@@ -133,29 +140,30 @@ if (empty($reshook))
$form = new Form($db);
$title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
-if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) $title = $object->lastname;
+if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
+ $title = $object->lastname;
+}
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('', $title, $help_url);
-if ($socid > 0)
-{
+if ($socid > 0) {
$objsoc = new Societe($db);
$objsoc->fetch($socid);
}
-if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
-{
+if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
- if (empty($object->error) && $id)
- {
- $object = new Contact($db);
- $result = $object->fetch($id);
- if ($result <= 0) dol_print_error('', $object->error);
- }
- $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
+ if (empty($object->error) && $id) {
+ $object = new Contact($db);
+ $result = $object->fetch($id);
+ if ($result <= 0) {
+ dol_print_error('', $object->error);
+ }
+ }
+ $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
$objcanvas->display_canvas($action); // Show template
} else {
// -----------------------------------------
@@ -163,26 +171,27 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// -----------------------------------------
// Confirm deleting contact
- if ($user->rights->societe->contact->supprimer)
- {
- if ($action == 'delete')
- {
+ if ($user->rights->societe->contact->supprimer) {
+ if ($action == 'delete') {
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage ? '&backtopage='.$backtopage : ''), $langs->trans("DeleteContact"), $langs->trans("ConfirmDeleteContact"), "confirm_delete", '', 0, 1);
}
}
/*
- * Onglets
- */
+ * Onglets
+ */
$head = array();
- if ($id > 0)
- {
+ if ($id > 0) {
// Si edition contact deja existant
$object = new Contact($db);
$res = $object->fetch($id, $user);
- if ($res < 0) { dol_print_error($db, $object->error); exit; }
+ if ($res < 0) {
+ dol_print_error($db, $object->error); exit;
+ }
$res = $object->fetch_optionals();
- if ($res < 0) { dol_print_error($db, $object->error); exit; }
+ if ($res < 0) {
+ dol_print_error($db, $object->error); exit;
+ }
// Show tabs
$head = contact_prepare_head($object);
@@ -190,13 +199,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
}
- if (!empty($id) && $action != 'edit' && $action != 'create')
- {
+ if (!empty($id) && $action != 'edit' && $action != 'create') {
$objsoc = new Societe($db);
/*
- * Fiche en mode visualisation
- */
+ * Fiche en mode visualisation
+ */
dol_htmloutput_errors($error, $errors);
@@ -205,14 +213,16 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$linkback = ''.$langs->trans("BackToList").' ';
$morehtmlref = '';
- if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
- {
+ if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
$objsoc = new Societe($db);
$objsoc->fetch($object->socid);
// Thirdparty
$morehtmlref .= $langs->trans('ThirdParty').' : ';
- if ($objsoc->id > 0) $morehtmlref .= $objsoc->getNomUrl(1);
- else $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+ if ($objsoc->id > 0) {
+ $morehtmlref .= $objsoc->getNomUrl(1);
+ } else {
+ $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+ }
}
$morehtmlref .= '
';
@@ -238,29 +248,31 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$out = '';
$permok = $user->rights->agenda->myactions->create;
- if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok)
- {
- if (is_object($objthirdparty) && get_class($objthirdparty) == 'Societe') $out .= '&originid='.$objthirdparty->id.($objthirdparty->id > 0 ? '&socid='.$objthirdparty->id : '');
+ if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
+ if (is_object($objthirdparty) && get_class($objthirdparty) == 'Societe') {
+ $out .= '&originid='.$objthirdparty->id.($objthirdparty->id > 0 ? '&socid='.$objthirdparty->id : '');
+ }
$out .= (!empty($objcon->id) ? '&contactid='.$objcon->id : '').'&origin=contact&originid='.$object->id.'&percentage=-1&backtopage='.urlencode($_SERVER['PHP_SELF'].($objcon->id > 0 ? '?id='.$objcon->id : ''));
$out .= '&datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog'));
}
$newcardbutton = '';
- 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)) {
$newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
}
}
- if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read)))
- {
- print ' ';
+ if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
+ print ' ';
$param = '&id='.$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("ActionsOnContact"), $newcardbutton, '');
//print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1);
diff --git a/htdocs/contact/canvas/actions_contactcard_common.class.php b/htdocs/contact/canvas/actions_contactcard_common.class.php
index f6f6fa0b45e..a32263cd65e 100644
--- a/htdocs/contact/canvas/actions_contactcard_common.class.php
+++ b/htdocs/contact/canvas/actions_contactcard_common.class.php
@@ -64,14 +64,16 @@ abstract class ActionsContactCardCommon
{
/*$ret = $this->getInstanceDao();
- if (is_object($this->object) && method_exists($this->object,'fetch'))
- {
- if (! empty($id)) $this->object->fetch($id);
- }
- else
- {*/
+ if (is_object($this->object) && method_exists($this->object,'fetch'))
+ {
+ if (! empty($id)) $this->object->fetch($id);
+ }
+ else
+ {*/
$object = new Contact($this->db);
- if (!empty($id)) $object->fetch($id);
+ if (!empty($id)) {
+ $object->fetch($id);
+ }
$this->object = $object;
//}
}
@@ -90,20 +92,19 @@ abstract class ActionsContactCardCommon
global $conf, $langs, $user, $canvas;
global $form, $formcompany, $objsoc;
- if ($action == 'add' || $action == 'update') $this->assign_post();
+ if ($action == 'add' || $action == 'update') {
+ $this->assign_post();
+ }
- foreach ($this->object as $key => $value)
- {
+ foreach ($this->object as $key => $value) {
$this->tpl[$key] = $value;
}
$this->tpl['error'] = $this->error;
$this->tpl['errors'] = $this->errors;
- if ($action == 'create' || $action == 'edit')
- {
- if ($conf->use_javascript_ajax)
- {
+ if ($action == 'create' || $action == 'edit') {
+ if ($conf->use_javascript_ajax) {
$this->tpl['ajax_selectcountry'] = "\n".''."\n";
}
- if (is_object($objsoc) && $objsoc->id > 0)
- {
+ if (is_object($objsoc) && $objsoc->id > 0) {
$this->tpl['company'] = $objsoc->getNomUrl(1);
$this->tpl['company_id'] = $objsoc->id;
} else {
@@ -127,14 +127,25 @@ abstract class ActionsContactCardCommon
$this->tpl['select_civility'] = $formcompany->select_civility($this->object->civility_id);
// Predefined with third party
- if ((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS))
- {
- if (dol_strlen(trim($this->object->address)) == 0) $this->tpl['address'] = $objsoc->address;
- if (dol_strlen(trim($this->object->zip)) == 0) $this->object->zip = $objsoc->zip;
- if (dol_strlen(trim($this->object->town)) == 0) $this->object->town = $objsoc->town;
- if (dol_strlen(trim($this->object->phone_pro)) == 0) $this->object->phone_pro = $objsoc->phone;
- if (dol_strlen(trim($this->object->fax)) == 0) $this->object->fax = $objsoc->fax;
- if (dol_strlen(trim($this->object->email)) == 0) $this->object->email = $objsoc->email;
+ if ((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) {
+ if (dol_strlen(trim($this->object->address)) == 0) {
+ $this->tpl['address'] = $objsoc->address;
+ }
+ if (dol_strlen(trim($this->object->zip)) == 0) {
+ $this->object->zip = $objsoc->zip;
+ }
+ if (dol_strlen(trim($this->object->town)) == 0) {
+ $this->object->town = $objsoc->town;
+ }
+ if (dol_strlen(trim($this->object->phone_pro)) == 0) {
+ $this->object->phone_pro = $objsoc->phone;
+ }
+ if (dol_strlen(trim($this->object->fax)) == 0) {
+ $this->object->fax = $objsoc->fax;
+ }
+ if (dol_strlen(trim($this->object->email)) == 0) {
+ $this->object->email = $objsoc->email;
+ }
}
// Zip
@@ -143,28 +154,33 @@ abstract class ActionsContactCardCommon
// Town
$this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
- if (dol_strlen(trim($this->object->country_id)) == 0) $this->object->country_id = $objsoc->country_id;
+ if (dol_strlen(trim($this->object->country_id)) == 0) {
+ $this->object->country_id = $objsoc->country_id;
+ }
// Country
$this->tpl['select_country'] = $form->select_country($this->object->country_id, 'country_id');
$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
- if ($user->admin) $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
+ if ($user->admin) {
+ $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
+ }
// State
- if ($this->object->country_id) $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
- else $this->tpl['select_state'] = $countrynotdefined;
+ if ($this->object->country_id) {
+ $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
+ } else {
+ $this->tpl['select_state'] = $countrynotdefined;
+ }
// Public or private
$selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
$this->tpl['select_visibility'] = $form->selectarray('priv', $selectarray, $this->object->priv, 0);
}
- if ($action == 'view' || $action == 'edit' || $action == 'delete')
- {
+ if ($action == 'view' || $action == 'edit' || $action == 'delete') {
// Emailing
- if (!empty($conf->mailing->enabled))
- {
+ if (!empty($conf->mailing->enabled)) {
$langs->load("mails");
$this->tpl['nb_emailing'] = $this->object->getNbOfEMailings();
}
@@ -175,46 +191,41 @@ abstract class ActionsContactCardCommon
$this->object->load_ref_elements();
- if (!empty($conf->commande->enabled))
- {
+ if (!empty($conf->commande->enabled)) {
$this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForOrders");
$this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_commande ? $this->object->ref_commande : $langs->trans("NoContactForAnyOrder");
$i++;
}
- if (!empty($conf->propal->enabled))
- {
+ if (!empty($conf->propal->enabled)) {
$this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForProposals");
$this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_propal ? $this->object->ref_propal : $langs->trans("NoContactForAnyProposal");
$i++;
}
- if (!empty($conf->contrat->enabled))
- {
+ if (!empty($conf->contrat->enabled)) {
$this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForContracts");
$this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_contrat ? $this->object->ref_contrat : $langs->trans("NoContactForAnyContract");
$i++;
}
- if (!empty($conf->facture->enabled))
- {
+ if (!empty($conf->facture->enabled)) {
$this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForInvoices");
$this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_facturation ? $this->object->ref_facturation : $langs->trans("NoContactForAnyInvoice");
$i++;
}
// Dolibarr user
- if ($this->object->user_id)
- {
+ if ($this->object->user_id) {
$dolibarr_user = new User($this->db);
$result = $dolibarr_user->fetch($this->object->user_id);
$this->tpl['dolibarr_user'] = $dolibarr_user->getLoginUrl(1);
- } else $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess");
+ } else {
+ $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess");
+ }
}
- if ($action == 'view' || $action == 'delete')
- {
+ if ($action == 'view' || $action == 'delete') {
$this->tpl['showrefnav'] = $form->showrefnav($this->object, 'id');
- if ($this->object->socid > 0)
- {
+ if ($this->object->socid > 0) {
$objsoc = new Societe($this->db);
$objsoc->fetch($this->object->socid);
@@ -243,14 +254,13 @@ abstract class ActionsContactCardCommon
$this->tpl['note'] = nl2br($this->object->note);
}
- if ($action == 'create_user')
- {
+ if ($action == 'create_user') {
// Full firstname and lastname separated with a dot : firstname.lastname
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
$login = dol_buildlogin($this->object->lastname, $this->object->firstname);
- $generated_password = getRandomPassword(false);
+ $generated_password = getRandomPassword(false);
$password = $generated_password;
// Create a form array
@@ -297,12 +307,10 @@ abstract class ActionsContactCardCommon
$this->object->canvas = $_POST["canvas"];
// We set country_id, and country_code label of the chosen country
- if ($this->object->country_id)
- {
+ if ($this->object->country_id) {
$sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_country WHERE rowid = ".$this->object->country_id;
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$obj = $this->db->fetch_object($resql);
} else {
dol_print_error($this->db);
diff --git a/htdocs/contact/canvas/default/tpl/contactcard_create.tpl.php b/htdocs/contact/canvas/default/tpl/contactcard_create.tpl.php
index 98a66e499b9..bd5cf24e195 100644
--- a/htdocs/contact/canvas/default/tpl/contactcard_create.tpl.php
+++ b/htdocs/contact/canvas/default/tpl/contactcard_create.tpl.php
@@ -16,8 +16,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;
}
diff --git a/htdocs/contact/canvas/default/tpl/contactcard_edit.tpl.php b/htdocs/contact/canvas/default/tpl/contactcard_edit.tpl.php
index 2c82a868ed4..41fbdb5def9 100644
--- a/htdocs/contact/canvas/default/tpl/contactcard_edit.tpl.php
+++ b/htdocs/contact/canvas/default/tpl/contactcard_edit.tpl.php
@@ -16,8 +16,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;
}
diff --git a/htdocs/contact/canvas/default/tpl/contactcard_view.tpl.php b/htdocs/contact/canvas/default/tpl/contactcard_view.tpl.php
index 43fd48e3ef0..c624eca4026 100644
--- a/htdocs/contact/canvas/default/tpl/contactcard_view.tpl.php
+++ b/htdocs/contact/canvas/default/tpl/contactcard_view.tpl.php
@@ -16,8 +16,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;
}
@@ -30,8 +29,12 @@ echo $this->control->tpl['showhead'];
dol_htmloutput_errors($this->control->tpl['error'], $this->control->tpl['errors']);
-if (!empty($this->control->tpl['action_create_user'])) echo $this->control->tpl['action_create_user'];
-if (!empty($this->control->tpl['action_delete'])) echo $this->control->tpl['action_delete']; ?>
+if (!empty($this->control->tpl['action_create_user'])) {
+ echo $this->control->tpl['action_create_user'];
+}
+if (!empty($this->control->tpl['action_delete'])) {
+ echo $this->control->tpl['action_delete'];
+} ?>
diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php
index 943c704b17f..0def459d444 100644
--- a/htdocs/contact/card.php
+++ b/htdocs/contact/card.php
@@ -71,24 +71,26 @@ $socialnetworks = getArrayOfSocialNetworks();
$object->getCanvas($id);
$objcanvas = null;
$canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
-if (!empty($canvas))
-{
+if (!empty($canvas)) {
require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
$objcanvas = new Canvas($db, $action);
$objcanvas->getCanvas('contact', 'contactcard', $canvas);
}
// Security check
-if ($user->socid) $socid = $user->socid;
+if ($user->socid) {
+ $socid = $user->socid;
+}
$result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('contactcard', 'globalcard'));
-if ($id > 0) $object->fetch($id);
+if ($id > 0) {
+ $object->fetch($id);
+}
-if (!($object->id > 0) && $action == 'view')
-{
+if (!($object->id > 0) && $action == 'view') {
$langs->load("errors");
print($langs->trans('ErrorRecordNotFound'));
exit;
@@ -100,36 +102,32 @@ if (!($object->id > 0) && $action == 'view')
$parameters = array('id'=>$id, 'objcanvas'=>$objcanvas);
$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)) {
// Cancel
- if (GETPOST('cancel', 'alpha') && !empty($backtopage))
- {
+ if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
header("Location: ".$backtopage);
exit;
}
// Creation utilisateur depuis contact
- if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer)
- {
+ if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) {
// Recuperation contact actuel
$result = $object->fetch($id);
- if ($result > 0)
- {
+ if ($result > 0) {
$db->begin();
// Creation user
$nuser = new User($db);
$result = $nuser->create_from_contact($object, GETPOST("login")); // Do not use GETPOST(alpha)
- if ($result > 0)
- {
+ if ($result > 0) {
$result2 = $nuser->setPassword($user, GETPOST("password"), 0, 0, 1); // Do not use GETPOST(alpha)
- if ($result2)
- {
+ if ($result2) {
$db->commit();
} else {
$error = $nuser->error; $errors = $nuser->errors;
@@ -146,11 +144,9 @@ if (empty($reshook))
// Confirmation desactivation
- if ($action == 'disable')
- {
+ if ($action == 'disable') {
$object->fetch($id);
- if ($object->setstatus(0) < 0)
- {
+ if ($object->setstatus(0) < 0) {
setEventMessages($object->error, $object->errors, 'errors');
} else {
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
@@ -159,11 +155,9 @@ if (empty($reshook))
}
// Confirmation activation
- if ($action == 'enable')
- {
+ if ($action == 'enable') {
$object->fetch($id);
- if ($object->setstatus(1) < 0)
- {
+ if ($object->setstatus(1) < 0) {
setEventMessages($object->error, $object->errors, 'errors');
} else {
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
@@ -172,11 +166,12 @@ if (empty($reshook))
}
// Add contact
- if ($action == 'add' && $user->rights->societe->contact->creer)
- {
+ if ($action == 'add' && $user->rights->societe->contact->creer) {
$db->begin();
- if ($canvas) $object->canvas = $canvas;
+ if ($canvas) {
+ $object->canvas = $canvas;
+ }
$object->entity = (GETPOSTISSET('entity') ?GETPOST('entity', 'int') : $conf->entity);
$object->socid = GETPOST("socid", 'int');
@@ -221,8 +216,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object);
- if ($ret < 0)
- {
+ if ($ret < 0) {
$error++;
$action = 'create';
}
@@ -233,8 +227,7 @@ if (empty($reshook))
$action = 'create';
}
- if (!empty($object->email) && !isValidEMail($object->email))
- {
+ if (!empty($object->email) && !isValidEMail($object->email)) {
$langs->load("errors");
$error++;
$errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
@@ -279,11 +272,13 @@ if (empty($reshook))
}
}
- if (empty($error) && $id > 0)
- {
+ if (empty($error) && $id > 0) {
$db->commit();
- if (!empty($backtopage)) $url = $backtopage;
- else $url = 'card.php?id='.$id;
+ if (!empty($backtopage)) {
+ $url = $backtopage;
+ } else {
+ $url = 'card.php?id='.$id;
+ }
header("Location: ".$url);
exit;
} else {
@@ -291,8 +286,7 @@ if (empty($reshook))
}
}
- if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->contact->supprimer)
- {
+ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->contact->supprimer) {
$result = $object->fetch($id);
$object->oldcopy = clone $object;
@@ -313,10 +307,8 @@ if (empty($reshook))
}
}
- if ($action == 'update' && empty($cancel) && $user->rights->societe->contact->creer)
- {
- if (!GETPOST("lastname", 'alpha'))
- {
+ if ($action == 'update' && empty($cancel) && $user->rights->societe->contact->creer) {
+ if (!GETPOST("lastname", 'alpha')) {
$error++; $errors = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
$action = 'edit';
}
@@ -327,16 +319,14 @@ if (empty($reshook))
$action = 'edit';
}
- if (!empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)) && !isValidEMail(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)))
- {
+ if (!empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)) && !isValidEMail(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL))) {
$langs->load("errors");
$error++;
$errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
$action = 'edit';
}
- if (!$error)
- {
+ if (!$error) {
$contactid = GETPOST("contactid", 'int');
$object->fetch($contactid);
$object->fetchRoles($contactid);
@@ -344,27 +334,22 @@ if (empty($reshook))
// Photo save
$dir = $conf->societe->multidir_output[$object->entity]."/contact/".$object->id."/photos";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
- if (GETPOST('deletephoto') && $object->photo)
- {
+ if (GETPOST('deletephoto') && $object->photo) {
$fileimg = $dir.'/'.$object->photo;
$dirthumbs = $dir.'/thumbs';
dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs);
$object->photo = '';
}
- if ($file_OK)
- {
- if (image_format_supported($_FILES['photo']['name']) > 0)
- {
+ if ($file_OK) {
+ if (image_format_supported($_FILES['photo']['name']) > 0) {
dol_mkdir($dir);
- if (@is_dir($dir))
- {
+ if (@is_dir($dir)) {
$newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
- if (!$result > 0)
- {
+ if (!$result > 0) {
$errors[] = "ErrorFailedToSaveFile";
} else {
$object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
@@ -377,8 +362,7 @@ if (empty($reshook))
$errors[] = "ErrorBadImageFormat";
}
} else {
- switch ($_FILES['photo']['error'])
- {
+ switch ($_FILES['photo']['error']) {
case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
$errors[] = "ErrorFileSizeTooLarge";
@@ -433,10 +417,11 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object);
- if ($ret < 0) $error++;
+ if ($ret < 0) {
+ $error++;
+ }
- if (!$error)
- {
+ if (!$error) {
$result = $object->update($contactid, $user);
if ($result > 0) {
@@ -445,8 +430,7 @@ if (empty($reshook))
$object->setCategories($categories);
// Update mass emailing flag into table mailing_unsubscribe
- if (GETPOSTISSET('no_email') && $object->email)
- {
+ if (GETPOSTISSET('no_email') && $object->email) {
$no_email = GETPOST('no_email', 'int');
$result=$object->setNoEmail($no_email);
if ($result<0) {
@@ -465,31 +449,31 @@ if (empty($reshook))
}
}
- if (!$error && empty($errors))
- {
- if (!empty($backtopage))
- {
- header("Location: ".$backtopage);
- exit;
- }
+ if (!$error && empty($errors)) {
+ if (!empty($backtopage)) {
+ header("Location: ".$backtopage);
+ exit;
+ }
}
}
- if ($action == 'setprospectcontactlevel' && $user->rights->societe->contact->creer)
- {
+ if ($action == 'setprospectcontactlevel' && $user->rights->societe->contact->creer) {
$object->fetch($id);
$object->fk_prospectlevel = GETPOST('prospect_contact_level_id', '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');
+ }
}
// set communication status
- if ($action == 'setstcomm')
- {
+ if ($action == 'setstcomm') {
$object->fetch($id);
$object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
$result = $object->update($object->id, $user);
- if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
+ if ($result < 0) {
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
}
// Actions to send emails
@@ -506,7 +490,9 @@ if (empty($reshook))
$title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
-if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) $title = $object->lastname;
+if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
+ $title = $object->lastname;
+}
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('', $title, $help_url);
@@ -515,24 +501,23 @@ $formcompany = new FormCompany($db);
$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
-if ($socid > 0)
-{
+if ($socid > 0) {
$objsoc = new Societe($db);
$objsoc->fetch($socid);
}
-if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
-{
+if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
- if (empty($object->error) && $id)
- {
- $object = new Contact($db);
- $result = $object->fetch($id);
- if ($result <= 0) dol_print_error('', $object->error);
- }
- $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
+ if (empty($object->error) && $id) {
+ $object = new Contact($db);
+ $result = $object->fetch($id);
+ if ($result <= 0) {
+ dol_print_error('', $object->error);
+ }
+ }
+ $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
$objcanvas->display_canvas($action); // Show template
} else {
// -----------------------------------------
@@ -540,20 +525,17 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// -----------------------------------------
// Confirm deleting contact
- if ($user->rights->societe->contact->supprimer)
- {
- if ($action == 'delete')
- {
+ if ($user->rights->societe->contact->supprimer) {
+ if ($action == 'delete') {
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage ? '&backtopage='.$backtopage : ''), $langs->trans("DeleteContact"), $langs->trans("ConfirmDeleteContact"), "confirm_delete", '', 0, 1);
}
}
/*
- * Onglets
- */
+ * Onglets
+ */
$head = array();
- if ($id > 0)
- {
+ if ($id > 0) {
// Si edition contact deja existant
$object = new Contact($db);
$res = $object->fetch($id, $user);
@@ -569,21 +551,18 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
}
- if ($user->rights->societe->contact->creer)
- {
- if ($action == 'create')
- {
+ if ($user->rights->societe->contact->creer) {
+ if ($action == 'create') {
/*
- * Fiche en mode creation
- */
+ * Fiche en mode creation
+ */
$object->canvas = $canvas;
$object->state_id = GETPOST("state_id");
// We set country_id, country_code and label for the selected country
$object->country_id = $_POST["country_id"] ?GETPOST("country_id") : (empty($objsoc->country_id) ? $mysoc->country_id : $objsoc->country_id);
- if ($object->country_id)
- {
+ if ($object->country_id) {
$tmparray = getCountry($object->country_id, 'all');
$object->country_code = $tmparray['code'];
$object->country = $tmparray['label'];
@@ -596,8 +575,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// Show errors
dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
- if ($conf->use_javascript_ajax)
- {
+ if ($conf->use_javascript_ajax) {
print "\n".''."\n";
}
- if (!GETPOSTISSET("no_email") && !empty($object->email))
- {
+ if (!GETPOSTISSET("no_email") && !empty($object->email)) {
$result=$object->getNoEmail();
if ($result<0) {
setEventMessages($object->error, $object->errors, 'errors');
@@ -821,7 +812,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print ''.$langs->trans("ContactByDefaultFor").' ';
print '';
$contactType = $object->listeTypeContacts('external', '', 1);
- print $form->multiselectarray('roles', $contactType);
+ print $form->multiselectarray('roles', $contactType, array(), 0, 0, 'minwidth500');
print ' ';
}
@@ -829,8 +820,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$parameters = array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook))
- {
+ if (empty($reshook)) {
print $object->showOptionals($extrafields, 'edit', $parameters);
}
@@ -846,8 +836,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// Date To Birth
print ''.$langs->trans("DateOfBirth").' ';
$form = new Form($db);
- if ($object->birthday)
- {
+ if ($object->birthday) {
print $form->selectDate($object->birthday, 'birthday', 0, 0, 0, "perso", 1, 0);
} else {
print $form->selectDate('', 'birthday', 0, 0, 1, "perso", 1, 0);
@@ -855,8 +844,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print ' ';
print ''.$langs->trans("Alert").' : ';
- if ($object->birthday_alert)
- {
+ if ($object->birthday_alert) {
print ' ';
} else {
print ' ';
@@ -870,8 +858,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print '';
print '
';
- if (!empty($backtopage))
- {
+ if (!empty($backtopage)) {
print ' ';
print '
';
} else {
@@ -883,12 +870,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print "";
} elseif ($action == 'edit' && !empty($id)) {
/*
- * Fiche en mode edition
- */
+ * Fiche en mode edition
+ */
// We set country_id, and country_code label of the chosen country
- if (GETPOSTISSET("country_id") || $object->country_id)
- {
+ if (GETPOSTISSET("country_id") || $object->country_id) {
$tmparray = getCountry($object->country_id, 'all');
$object->country_code = $tmparray['code'];
$object->country = $tmparray['label'];
@@ -900,8 +886,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// Show errors
dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
- if ($conf->use_javascript_ajax)
- {
+ if ($conf->use_javascript_ajax) {
print "\n".''."\n";
}
- if (!GETPOSTISSET("no_email") && !empty($object->email))
- {
+ if (!GETPOSTISSET("no_email") && !empty($object->email)) {
$result=$object->getNoEmail();
if ($result<0) {
setEventMessages($object->error, $object->errors, 'errors');
@@ -1145,36 +1128,31 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$parameters = array('colspan' => ' colspan="3"', 'cols'=> '3');
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook))
- {
+ if (empty($reshook)) {
print $object->showOptionals($extrafields, 'edit', $parameters);
}
$object->load_ref_elements();
- if (!empty($conf->commande->enabled))
- {
+ if (!empty($conf->commande->enabled)) {
print '
'.$langs->trans("ContactForOrders").' ';
print $object->ref_commande ? $object->ref_commande : $langs->trans("NoContactForAnyOrder");
print ' ';
}
- if (!empty($conf->propal->enabled))
- {
+ if (!empty($conf->propal->enabled)) {
print '
'.$langs->trans("ContactForProposals").' ';
print $object->ref_propal ? $object->ref_propal : $langs->trans("NoContactForAnyProposal");
print ' ';
}
- if (!empty($conf->contrat->enabled))
- {
+ if (!empty($conf->contrat->enabled)) {
print '
'.$langs->trans("ContactForContracts").' ';
print $object->ref_contrat ? $object->ref_contrat : $langs->trans("NoContactForAnyContract");
print ' ';
}
- if (!empty($conf->facture->enabled))
- {
+ if (!empty($conf->facture->enabled)) {
print '
'.$langs->trans("ContactForInvoices").' ';
print $object->ref_facturation ? $object->ref_facturation : $langs->trans("NoContactForAnyInvoice");
print ' ';
@@ -1182,12 +1160,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// Login Dolibarr
print '
'.$langs->trans("DolibarrLogin").' ';
- if ($object->user_id)
- {
+ if ($object->user_id) {
$dolibarr_user = new User($db);
$result = $dolibarr_user->fetch($object->user_id);
print $dolibarr_user->getLoginUrl(1);
- } else print $langs->trans("NoDolibarrAccess");
+ } else {
+ print $langs->trans("NoDolibarrAccess");
+ }
print ' ';
// Photo
@@ -1199,7 +1178,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print "
\n";
}
print '
';
@@ -1226,8 +1207,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$action = 'presend';
}
- if (!empty($id) && $action != 'edit' && $action != 'create')
- {
+ if (!empty($id) && $action != 'edit' && $action != 'create') {
$objsoc = new Societe($db);
// View mode
@@ -1237,15 +1217,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print dol_get_fiche_head($head, 'card', $title, -1, 'contact');
- if ($action == 'create_user')
- {
+ if ($action == 'create_user') {
// Full firstname and lastname separated with a dot : firstname.lastname
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$login = dol_buildlogin($object->lastname, $object->firstname);
$generated_password = '';
- if (!$ldap_sid) // TODO ldap_sid ?
- {
+ if (!$ldap_sid) { // TODO ldap_sid ?
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
$generated_password = getRandomPassword(false);
}
@@ -1258,10 +1236,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
//array('label' => $form->textwithpicto($langs->trans("Type"),$langs->trans("InternalExternalDesc")), 'type' => 'select', 'name' => 'intern', 'default' => 1, 'values' => array(0=>$langs->trans('Internal'),1=>$langs->trans('External')))
);
$text = $langs->trans("ConfirmCreateContact").'
';
- if (!empty($conf->societe->enabled))
- {
- if ($object->socid > 0) $text .= $langs->trans("UserWillBeExternalUser");
- else $text .= $langs->trans("UserWillBeInternalUser");
+ if (!empty($conf->societe->enabled)) {
+ if ($object->socid > 0) {
+ $text .= $langs->trans("UserWillBeExternalUser");
+ } else {
+ $text .= $langs->trans("UserWillBeInternalUser");
+ }
}
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
}
@@ -1269,13 +1249,15 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$linkback = '
'.$langs->trans("BackToList").' ';
$morehtmlref = '
';
- if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
- {
+ if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
$objsoc->fetch($object->socid);
// Thirdparty
$morehtmlref .= $langs->trans('ThirdParty').' : ';
- if ($objsoc->id > 0) $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
- else $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+ if ($objsoc->id > 0) {
+ $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
+ } else {
+ $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+ }
}
$morehtmlref .= '
';
@@ -1297,16 +1279,14 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print '
'.$langs->trans("PostOrFunction").' '.$object->poste.' ';
// Email
- if (!empty($conf->mailing->enabled))
- {
+ if (!empty($conf->mailing->enabled)) {
$langs->load("mails");
print '
'.$langs->trans("NbOfEMailingsSend").' ';
print ''.$object->getNbOfEMailings().' ';
}
// Unsubscribe opt-out
- if (!empty($conf->mailing->enabled))
- {
+ if (!empty($conf->mailing->enabled)) {
$result=$object->getNoEmail();
if ($result<0) {
setEventMessages($object->error, $object->errors, 'errors');
@@ -1324,8 +1304,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$object->fetch_thirdparty();
if (!empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
- if ($object->thirdparty->client == 2 || $object->thirdparty->client == 3)
- {
+ if ($object->thirdparty->client == 2 || $object->thirdparty->client == 3) {
print '
';
print '
';
@@ -1336,7 +1315,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print '
';
print '
';
if ($action == 'editlevel') {
@@ -1354,8 +1335,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print '';
foreach ($object->cacheprospectstatus as $key => $val) {
$titlealt = 'default';
- if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) $titlealt = $val['label'];
- if ($object->stcomm_id != $val['id']) print '
id.'&stcomm='.$val['code'].'&action=setstcomm&token='.newToken().'">'.img_action($titlealt, $val['code'], $val['picto']).' ';
+ if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
+ $titlealt = $val['label'];
+ }
+ if ($object->stcomm_id != $val['id']) {
+ print '
id.'&stcomm='.$val['code'].'&action=setstcomm&token='.newToken().'">'.img_action($titlealt, $val['code'], $val['picto']).' ';
+ }
}
print '
';
@@ -1391,45 +1376,48 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$object->load_ref_elements();
- if (!empty($conf->propal->enabled))
- {
+ if (!empty($conf->propal->enabled)) {
print ''.$langs->trans("ContactForProposals").' ';
print $object->ref_propal ? $object->ref_propal : $langs->trans("NoContactForAnyProposal");
print ' ';
}
- if (!empty($conf->commande->enabled) || !empty($conf->expedition->enabled))
- {
+ if (!empty($conf->commande->enabled) || !empty($conf->expedition->enabled)) {
print '';
- if (!empty($conf->expedition->enabled)) { print $langs->trans("ContactForOrdersOrShipments"); } else print $langs->trans("ContactForOrders");
+ if (!empty($conf->expedition->enabled)) {
+ print $langs->trans("ContactForOrdersOrShipments");
+ } else {
+ print $langs->trans("ContactForOrders");
+ }
print ' ';
$none = $langs->trans("NoContactForAnyOrder");
- if (!empty($conf->expedition->enabled)) { $none = $langs->trans("NoContactForAnyOrderOrShipments"); }
+ if (!empty($conf->expedition->enabled)) {
+ $none = $langs->trans("NoContactForAnyOrderOrShipments");
+ }
print $object->ref_commande ? $object->ref_commande : $none;
print ' ';
}
- if (!empty($conf->contrat->enabled))
- {
+ if (!empty($conf->contrat->enabled)) {
print ''.$langs->trans("ContactForContracts").' ';
print $object->ref_contrat ? $object->ref_contrat : $langs->trans("NoContactForAnyContract");
print ' ';
}
- if (!empty($conf->facture->enabled))
- {
+ if (!empty($conf->facture->enabled)) {
print ''.$langs->trans("ContactForInvoices").' ';
print $object->ref_facturation ? $object->ref_facturation : $langs->trans("NoContactForAnyInvoice");
print ' ';
}
print ''.$langs->trans("DolibarrLogin").' ';
- if ($object->user_id)
- {
+ if ($object->user_id) {
$dolibarr_user = new User($db);
$result = $dolibarr_user->fetch($object->user_id);
print $dolibarr_user->getLoginUrl(1);
- } else print $langs->trans("NoDolibarrAccess");
+ } else {
+ print $langs->trans("NoDolibarrAccess");
+ }
print ' ';
print '';
@@ -1452,11 +1440,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- if (empty($reshook) && $action != 'presend')
- {
+ if (empty($reshook) && $action != 'presend') {
if (empty($user->socid)) {
- if (!empty($object->email))
- {
+ if (!empty($object->email)) {
$langs->load("mails");
print '';
} else {
@@ -1465,30 +1451,25 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
}
}
- if ($user->rights->societe->contact->creer)
- {
+ if ($user->rights->societe->contact->creer) {
print ''.$langs->trans('Modify').' ';
}
- if (!$object->user_id && $user->rights->user->user->creer)
- {
+ if (!$object->user_id && $user->rights->user->user->creer) {
print ''.$langs->trans("CreateDolibarrLogin").' ';
}
// Activer
- if ($object->statut == 0 && $user->rights->societe->contact->creer)
- {
+ if ($object->statut == 0 && $user->rights->societe->contact->creer) {
print ''.$langs->trans("Reactivate").' ';
}
// Desactiver
- if ($object->statut == 1 && $user->rights->societe->contact->creer)
- {
+ if ($object->statut == 1 && $user->rights->societe->contact->creer) {
print ''.$langs->trans("DisableUser").' ';
}
// Delete
- if ($user->rights->societe->contact->supprimer)
- {
+ if ($user->rights->societe->contact->supprimer) {
print ''.$langs->trans('Delete').' ';
}
}
@@ -1500,8 +1481,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$action = 'presend';
}
- if ($action != 'presend')
- {
+ if ($action != 'presend') {
print '';
print '
';
diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php
index 1d2cb3355a5..0c7f3ac73aa 100644
--- a/htdocs/contact/class/contact.class.php
+++ b/htdocs/contact/class/contact.class.php
@@ -473,40 +473,35 @@ class Contact extends CommonObject
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople");
- if (!$error)
- {
+ if (!$error) {
$result = $this->update($this->id, $user, 1, 'add'); // This include updateRoles(), ...
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
$this->error = $this->db->lasterror();
}
}
- if (!$error)
- {
+ if (!$error) {
$result = $this->update_perso($this->id, $user, 1); // TODO Remove function update_perso, should be same than update
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
$this->error = $this->db->lasterror();
}
}
- if (!$error)
- {
+ if (!$error) {
// Call trigger
$result = $this->call_trigger('CONTACT_CREATE', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return $this->id;
} else {
@@ -558,13 +553,20 @@ class Contact extends CommonObject
$this->town = (empty($this->town) ? '' : trim($this->town));
$this->setUpperOrLowerCase();
$this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
- if (empty($this->statut)) $this->statut = 0;
- if (empty($this->civility_code) && !is_numeric($this->civility_id)) $this->civility_code = $this->civility_id; // For backward compatibility
+ if (empty($this->statut)) {
+ $this->statut = 0;
+ }
+ if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
+ $this->civility_code = $this->civility_id; // For backward compatibility
+ }
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET ";
- if ($this->socid > 0) $sql .= " fk_soc='".$this->db->escape($this->socid)."',";
- elseif ($this->socid == -1) $sql .= " fk_soc=null,";
+ if ($this->socid > 0) {
+ $sql .= " fk_soc='".$this->db->escape($this->socid)."',";
+ } elseif ($this->socid == -1) {
+ $sql .= " fk_soc=null,";
+ }
$sql .= " civility='".$this->db->escape($this->civility_code)."'";
$sql .= ", lastname='".$this->db->escape($this->lastname)."'";
$sql .= ", firstname='".$this->db->escape($this->firstname)."'";
@@ -586,8 +588,7 @@ class Contact extends CommonObject
$sql .= ", phone_mobile = ".(isset($this->phone_mobile) ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
$sql .= ", priv = '".$this->db->escape($this->priv)."'";
$sql .= ", fk_prospectcontactlevel = '".$this->db->escape($this->fk_prospectlevel)."'";
- if (isset($this->stcomm_id))
- {
+ if (isset($this->stcomm_id)) {
$sql .= ", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? $this->stcomm_id : "0");
}
$sql .= ", statut = ".$this->db->escape($this->statut);
@@ -598,8 +599,7 @@ class Contact extends CommonObject
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
unset($this->country_code);
unset($this->country);
unset($this->state_code);
@@ -608,25 +608,21 @@ class Contact extends CommonObject
$action = 'update';
// Actions on extra fields
- if (!$error)
- {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
if (!$error) {
$result = $this->updateRoles();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error && $this->user_id > 0)
- {
+ if (!$error && $this->user_id > 0) {
// If contact is linked to a user
$tmpobj = new User($this->db);
$tmpobj->fetch($this->user_id);
@@ -685,14 +681,18 @@ class Contact extends CommonObject
// }
if ($usermustbemodified) {
$result = $tmpobj->update($user, 0, 1, 1, 1);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
}
}
if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('CONTACT_MODIFY', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
@@ -759,34 +759,69 @@ class Contact extends CommonObject
$this->fullname = $this->getFullName($langs);
// Fields
- if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
- if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
- if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
+ if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
+ }
+ if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
+ }
+ if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
+ }
- if ($this->poste) $info["title"] = $this->poste;
+ if ($this->poste) {
+ $info["title"] = $this->poste;
+ }
if ($this->socid > 0) {
$soc = new Societe($this->db);
$soc->fetch($this->socid);
$info[$conf->global->LDAP_CONTACT_FIELD_COMPANY] = $soc->name;
- if ($soc->client == 1) $info["businessCategory"] = "Customers";
- if ($soc->client == 2) $info["businessCategory"] = "Prospects";
- if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers";
+ if ($soc->client == 1) {
+ $info["businessCategory"] = "Customers";
+ }
+ if ($soc->client == 2) {
+ $info["businessCategory"] = "Prospects";
+ }
+ if ($soc->fournisseur == 1) {
+ $info["businessCategory"] = "Suppliers";
+ }
+ }
+ if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
+ }
+ if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
+ }
+ if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
+ }
+ if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
+ }
+ if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
+ }
+ if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
+ }
+ if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
+ }
+ if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
+ }
+ if ($this->skype && !empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
+ }
+ if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
+ }
+ if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) {
+ $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
}
- if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
- if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
- if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
- if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
- if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
- if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
- if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
- if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX)) $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
- if ($this->skype && !empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
- if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
- if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
- if ($conf->global->LDAP_SERVER_TYPE == 'egroupware')
- {
+ if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') {
$info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware
$info['uidnumber'] = $this->id;
@@ -805,8 +840,12 @@ class Contact extends CommonObject
$info["phpgwContactOwner"] = $this->egroupware_id;
- if ($this->email) $info["rfc822Mailbox"] = $this->email;
- if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
+ if ($this->email) {
+ $info["rfc822Mailbox"] = $this->email;
+ }
+ if ($this->phone_mobile) {
+ $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
+ }
}
return $info;
@@ -834,13 +873,14 @@ class Contact extends CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
$sql .= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
$sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
- if ($user) $sql .= ", fk_user_modif=".$user->id;
+ if ($user) {
+ $sql .= ", fk_user_modif=".$user->id;
+ }
$sql .= " WHERE rowid=".$this->db->escape($id);
dol_syslog(get_class($this)."::update_perso this->birthday=".$this->birthday." -", LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$error++;
$this->error = $this->db->lasterror();
}
@@ -875,7 +915,9 @@ class Contact extends CommonObject
if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('CONTACT_MODIFY', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
@@ -906,8 +948,7 @@ class Contact extends CommonObject
dol_syslog(get_class($this)."::fetch id=".$id." ref_ext=".$ref_ext." email=".$email, LOG_DEBUG);
- if (empty($id) && empty($ref_ext) && empty($email))
- {
+ if (empty($id) && empty($ref_ext) && empty($email)) {
$this->error = 'BadParameter';
return -1;
}
@@ -936,8 +977,9 @@ class Contact extends CommonObject
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
- if ($id) $sql .= " WHERE c.rowid = ".((int) $id);
- else {
+ if ($id) {
+ $sql .= " WHERE c.rowid = ".((int) $id);
+ } else {
$sql .= " WHERE c.entity IN (".getEntity($this->element).")";
if ($ref_ext) {
$sql .= " AND c.ref_ext = '".$this->db->escape($ref_ext)."'";
@@ -948,17 +990,14 @@ class Contact extends CommonObject
}
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $this->db->num_rows($resql);
- if ($num > 1)
- {
+ if ($num > 1) {
$this->error = 'Fetch found several records. Rename one of contact to avoid duplicate.';
dol_syslog($this->error, LOG_ERR);
return 2;
- } elseif ($num) // $num = 1
- {
+ } elseif ($num) { // $num = 1
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@@ -1030,10 +1069,8 @@ class Contact extends CommonObject
$sql .= " WHERE u.fk_socpeople = ".$this->id;
$resql = $this->db->query($sql);
- if ($resql)
- {
- if ($this->db->num_rows($resql))
- {
+ if ($resql) {
+ if ($this->db->num_rows($resql)) {
$uobj = $this->db->fetch_object($resql);
$this->user_id = $uobj->rowid;
@@ -1049,17 +1086,14 @@ class Contact extends CommonObject
$this->fetch_optionals();
// Load also alerts of this user
- if ($user)
- {
+ if ($user) {
$sql = "SELECT fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
$sql .= " WHERE fk_user = ".$user->id." AND fk_contact = ".$this->db->escape($id);
$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->birthday_alert = 1;
@@ -1102,11 +1136,9 @@ class Contact extends CommonObject
{
unset($this->gender);
- if (in_array($this->civility_id, array('MR')) || in_array($this->civility_code, array('MR')))
- {
+ if (in_array($this->civility_id, array('MR')) || in_array($this->civility_code, array('MR'))) {
$this->gender = 'man';
- } elseif (in_array($this->civility_id, array('MME', 'MLE')) || in_array($this->civility_code, array('MME', 'MLE')))
- {
+ } elseif (in_array($this->civility_id, array('MME', 'MLE')) || in_array($this->civility_code, array('MME', 'MLE'))) {
$this->gender = 'woman';
}
}
@@ -1135,16 +1167,18 @@ class Contact extends CommonObject
dol_syslog(get_class($this)."::load_ref_elements", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
- while ($obj = $this->db->fetch_object($resql))
- {
- if ($obj->nb)
- {
- if ($obj->element == 'facture') $this->ref_facturation = $obj->nb;
- elseif ($obj->element == 'contrat') $this->ref_contrat = $obj->nb;
- elseif ($obj->element == 'commande') $this->ref_commande = $obj->nb;
- elseif ($obj->element == 'propal') $this->ref_propal = $obj->nb;
+ if ($resql) {
+ while ($obj = $this->db->fetch_object($resql)) {
+ if ($obj->nb) {
+ if ($obj->element == 'facture') {
+ $this->ref_facturation = $obj->nb;
+ } elseif ($obj->element == 'contrat') {
+ $this->ref_contrat = $obj->nb;
+ } elseif ($obj->element == 'commande') {
+ $this->ref_commande = $obj->nb;
+ } elseif ($obj->element == 'propal') {
+ $this->ref_propal = $obj->nb;
+ }
}
}
$this->db->free($resql);
@@ -1169,8 +1203,7 @@ class Contact extends CommonObject
$this->db->begin();
- if (!$error)
- {
+ if (!$error) {
// Get all rowid of element_contact linked to a type that is link to llx_socpeople
$sql = "SELECT ec.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
@@ -1180,21 +1213,18 @@ class Contact extends CommonObject
$sql .= " AND tc.source='external'";
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
- while ($i < $num && !$error)
- {
+ while ($i < $num && !$error) {
$obj = $this->db->fetch_object($resql);
$sqldel = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
$sqldel .= " WHERE rowid = ".$obj->rowid;
dol_syslog(__METHOD__, LOG_DEBUG);
$result = $this->db->query($sqldel);
- if (!$result)
- {
+ if (!$result) {
$error++;
$this->error = $this->db->error().' sql='.$sqldel;
}
@@ -1207,56 +1237,48 @@ class Contact extends CommonObject
}
}
- if (!$error)
- {
+ if (!$error) {
// Remove Roles
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".$this->id;
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$error++;
$this->error .= $this->db->lasterror();
$errorflag = -1;
}
}
- if (!$error)
- {
+ if (!$error) {
// Remove Roles
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".$this->id;
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$error++;
$this->error .= $this->db->lasterror();
$errorflag = -1;
}
}
- if (!$error)
- {
+ if (!$error) {
// Remove category
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople = ".$this->id;
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$error++;
$this->error .= $this->db->lasterror();
$errorflag = -1;
}
}
- if (!$error)
- {
+ if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
$sql .= " WHERE rowid=".$this->id;
dol_syslog(__METHOD__, LOG_DEBUG);
$result = $this->db->query($sql);
- if (!$result)
- {
+ if (!$result) {
$error++;
$this->error = $this->db->error().' sql='.$sql;
}
@@ -1266,19 +1288,21 @@ class Contact extends CommonObject
if (!$error) {
// For avoid conflicts if trigger used
$result = $this->deleteExtraFields();
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('CONTACT_DELETE', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
@@ -1303,10 +1327,8 @@ class Contact extends CommonObject
$sql .= " WHERE c.rowid = ".$this->db->escape($id);
$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;
@@ -1346,8 +1368,7 @@ class Contact extends CommonObject
$sql .= " AND m.entity IN (".getEntity($this->element).") AND mc.statut NOT IN (-1,0)"; // -1 error, 0 not sent, 1 sent with success
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$obj = $this->db->fetch_object($resql);
$nb = $obj->nb;
@@ -1377,8 +1398,7 @@ class Contact extends CommonObject
$result = ''; $label = '';
- if (!empty($this->photo) && class_exists('Form'))
- {
+ if (!empty($this->photo) && class_exists('Form')) {
$label .= '
';
$label .= Form::showphoto('contact', $this, 0, 40, 0, '', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
$label .= '
';
@@ -1388,67 +1408,83 @@ class Contact extends CommonObject
$label .= ' '.$this->getLibStatut(4);
$label .= '
'.$langs->trans("Name").': '.$this->getFullName($langs);
//if ($this->civility_id) $label.= '
' . $langs->trans("Civility") . ': '.$this->civility_id; // TODO Translate cibilty_id code
- if (!empty($this->poste)) $label .= '
'.$langs->trans("Poste").': '.$this->poste;
+ if (!empty($this->poste)) {
+ $label .= '
'.$langs->trans("Poste").': '.$this->poste;
+ }
$label .= '
'.$langs->trans("EMail").': '.$this->email;
$phonelist = array();
$country_code = empty($this->country_code) ? '': $this->country_code;
- if ($this->phone_pro) $phonelist[] = dol_print_phone($this->phone_pro, $country_code, $this->id, 0, '', ' ', 'phone');
- if ($this->phone_mobile) $phonelist[] = dol_print_phone($this->phone_mobile, $country_code, $this->id, 0, '', ' ', 'mobile');
- if ($this->phone_perso) $phonelist[] = dol_print_phone($this->phone_perso, $country_code, $this->id, 0, '', ' ', 'phone');
+ if ($this->phone_pro) {
+ $phonelist[] = dol_print_phone($this->phone_pro, $country_code, $this->id, 0, '', ' ', 'phone');
+ }
+ if ($this->phone_mobile) {
+ $phonelist[] = dol_print_phone($this->phone_mobile, $country_code, $this->id, 0, '', ' ', 'mobile');
+ }
+ if ($this->phone_perso) {
+ $phonelist[] = dol_print_phone($this->phone_perso, $country_code, $this->id, 0, '', ' ', 'phone');
+ }
$label .= '
'.$langs->trans("Phone").': '.implode(' ', $phonelist);
$label .= '
'.$langs->trans("Address").': '.dol_format_address($this, 1, ' ', $langs);
$url = DOL_URL_ROOT.'/contact/card.php?id='.$this->id;
- if ($option !== 'nolink')
- {
+ if ($option !== 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
- if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
- if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
}
$url .= $moreparam;
$linkclose = "";
if (empty($notooltip)) {
- if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
- {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowContact");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
- $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
- $linkclose .= ' class="classfortooltip"';
+ $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
+ $linkclose .= ' class="classfortooltip"';
- /*
- $hookmanager->initHooks(array('contactdao'));
- $parameters=array('id'=>$this->id);
- $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
- if ($reshook > 0) $linkclose = $hookmanager->resPrint;
- */
+ /*
+ $hookmanager->initHooks(array('contactdao'));
+ $parameters=array('id'=>$this->id);
+ $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
+ if ($reshook > 0) $linkclose = $hookmanager->resPrint;
+ */
}
$linkstart = '
';
$linkend = ' ';
- if ($option == 'xxx')
- {
+ if ($option == 'xxx') {
$linkstart = '
';
$linkend = ' ';
}
$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 .= ($maxlen ?dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs));
+ 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 .= ($maxlen ?dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs));
+ }
$result .= $linkend;
global $action;
$hookmanager->initHooks(array('contactdao'));
$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
- if ($reshook > 0) $result = $hookmanager->resPrint;
- else $result .= $hookmanager->resPrint;
+ if ($reshook > 0) {
+ $result = $hookmanager->resPrint;
+ } else {
+ $result .= $hookmanager->resPrint;
+ }
return $result;
}
@@ -1463,7 +1499,9 @@ class Contact extends CommonObject
global $langs;
$code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite : '')));
- if (empty($code)) return '';
+ if (empty($code)) {
+ return '';
+ }
$langs->load("dict");
return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
@@ -1507,7 +1545,9 @@ class Contact extends CommonObject
);
$statusType = 'status4';
- if ($status == 0 || $status == 5) $statusType = 'status5';
+ if ($status == 0 || $status == 5) {
+ $statusType = 'status5';
+ }
$label = $langs->trans($labelStatus[$status]);
$labelshort = $langs->trans($labelStatusShort[$status]);
@@ -1527,8 +1567,11 @@ class Contact extends CommonObject
{
// phpcs:enable
global $langs;
- if ($status == '1') return $langs->trans('ContactPrivate');
- else return $langs->trans('ContactPublic');
+ if ($status == '1') {
+ return $langs->trans('ContactPrivate');
+ } else {
+ return $langs->trans('ContactPublic');
+ }
}
@@ -1547,7 +1590,9 @@ class Contact extends CommonObject
$resql = $this->db->query($sql);
if ($resql) {
$obj = $this->db->fetch_object($resql);
- if ($obj) $socid = $obj->rowid;
+ if ($obj) {
+ $socid = $obj->rowid;
+ }
}
// Initialise parameters
@@ -1592,8 +1637,11 @@ class Contact extends CommonObject
$error = 0;
// Check parameters
- if ($this->statut == $status) return 0;
- else $this->statut = $status;
+ if ($this->statut == $status) {
+ return 0;
+ } else {
+ $this->statut = $status;
+ }
$this->db->begin();
@@ -1604,16 +1652,16 @@ class Contact extends CommonObject
$result = $this->db->query($sql);
dol_syslog(get_class($this)."::setstatus", LOG_DEBUG);
- if ($result)
- {
+ if ($result) {
// Call trigger
$result = $this->call_trigger('CONTACT_ENABLEDISABLE', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if ($error)
- {
+ if ($error) {
$this->db->rollback();
return -$error;
} else {
@@ -1725,12 +1773,10 @@ class Contact extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$tab[] = array('fk_socpeople'=>$obj->id, 'type_contact'=>$obj->fk_c_type_contact);
@@ -1758,11 +1804,13 @@ class Contact extends CommonObject
$error = 0;
- if (!isset($this->roles)) return; // Avoid to loose roles when property not set
+ if (!isset($this->roles)) {
+ return; // Avoid to loose roles when property not set
+ }
$this->db->begin();
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople=".$this->id." AND entity IN (".getEntity("societe_contact").")";
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople=".((int) $this->id)." AND entity IN (".getEntity("societe_contact").")";
$result = $this->db->query($sql);
if (!$result) {
@@ -1800,8 +1848,7 @@ class Contact extends CommonObject
$sql .= ")";
$result = $this->db->query($sql);
- if (!$result)
- {
+ if (!$result) {
$this->errors[] = $this->db->lasterror().' sql='.$sql;
$error++;
}
@@ -1830,12 +1877,13 @@ class Contact extends CommonObject
global $langs;
$sql = "SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX."c_stcommcontact";
- if ($active >= 0) $sql .= " WHERE active = ".$active;
+ if ($active >= 0) {
+ $sql .= " WHERE active = ".$active;
+ }
$resql = $this->db->query($sql);
$num = $this->db->num_rows($resql);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$this->cacheprospectstatus[$obj->id] = array('id' => $obj->id, 'code' => $obj->code, 'label' => ($langs->trans("ST_".strtoupper($obj->code)) == "ST_".strtoupper($obj->code)) ? $obj->label : $langs->trans("ST_".strtoupper($obj->code)), 'picto' => $obj->picto);
$i++;
@@ -1865,8 +1913,7 @@ class Contact extends CommonObject
$lib = $langs->trans("ProspectLevel".$fk_prospectlevel);
// If lib not found in language file, we get label from cache/databse
- if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
- {
+ if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel)) {
$lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label');
}
return $lib;
@@ -1915,36 +1962,48 @@ class Contact extends CommonObject
global $langs;
$langs->load('customers');
- if ($mode == 2)
- {
- if ($statut == '-1' || $statut == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
- elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
- elseif ($statut == '1' || $statut == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
- elseif ($statut == '2' || $statut == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
- elseif ($statut == '3' || $statut == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
- else {
+ if ($mode == 2) {
+ if ($statut == '-1' || $statut == 'ST_NO') {
+ return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
+ } elseif ($statut == '0' || $statut == 'ST_NEVER') {
+ return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
+ } elseif ($statut == '1' || $statut == 'ST_TODO') {
+ return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
+ } elseif ($statut == '2' || $statut == 'ST_PEND') {
+ return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
+ } elseif ($statut == '3' || $statut == 'ST_DONE') {
+ return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
+ } else {
return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
}
}
- if ($mode == 3)
- {
- if ($statut == '-1' || $statut == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto);
- elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto);
- elseif ($statut == '1' || $statut == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto);
- elseif ($statut == '2' || $statut == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto);
- elseif ($statut == '3' || $statut == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto);
- else {
+ if ($mode == 3) {
+ if ($statut == '-1' || $statut == 'ST_NO') {
+ return img_action($langs->trans("StatusProspect-1"), -1, $picto);
+ } elseif ($statut == '0' || $statut == 'ST_NEVER') {
+ return img_action($langs->trans("StatusProspect0"), 0, $picto);
+ } elseif ($statut == '1' || $statut == 'ST_TODO') {
+ return img_action($langs->trans("StatusProspect1"), 1, $picto);
+ } elseif ($statut == '2' || $statut == 'ST_PEND') {
+ return img_action($langs->trans("StatusProspect2"), 2, $picto);
+ } elseif ($statut == '3' || $statut == 'ST_DONE') {
+ return img_action($langs->trans("StatusProspect3"), 3, $picto);
+ } else {
return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto);
}
}
- if ($mode == 4)
- {
- if ($statut == '-1' || $statut == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
- elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
- elseif ($statut == '1' || $statut == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
- elseif ($statut == '2' || $statut == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
- elseif ($statut == '3' || $statut == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
- else {
+ if ($mode == 4) {
+ if ($statut == '-1' || $statut == 'ST_NO') {
+ return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
+ } elseif ($statut == '0' || $statut == 'ST_NEVER') {
+ return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
+ } elseif ($statut == '1' || $statut == 'ST_TODO') {
+ return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
+ } elseif ($statut == '2' || $statut == 'ST_PEND') {
+ return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
+ } elseif ($statut == '3' || $statut == 'ST_DONE') {
+ return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
+ } else {
return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
}
}
@@ -1964,24 +2023,19 @@ class Contact extends CommonObject
$error = 0;
// Update mass emailing flag into table mailing_unsubscribe
- if ($this->email)
- {
+ if ($this->email) {
$this->db->begin();
- if ($no_email)
- {
+ if ($no_email) {
$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing', 0).") AND email = '".$this->db->escape($this->email)."'";
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$obj = $this->db->fetch_object($resql);
$noemail = $obj->nb;
- if (empty($noemail))
- {
+ if (empty($noemail)) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe(email, entity, date_creat) VALUES ('".$this->db->escape($this->email)."', ".$this->db->escape(getEntity('mailing', 0)).", '".$this->db->idate(dol_now())."')";
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$error++;
$this->error = $this->db->lasterror();
$this->errors[] = $this->error;
@@ -1995,8 +2049,7 @@ class Contact extends CommonObject
} else {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = '".$this->db->escape($this->email)."' AND entity = ".$this->db->escape(getEntity('mailing', 0));
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$error++;
$this->error = $this->db->lasterror();
$this->errors[] = $this->error;
@@ -2024,8 +2077,7 @@ class Contact extends CommonObject
*/
public function getNoEmail()
{
- if ($this->email)
- {
+ if ($this->email) {
$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing').") AND email = '".$this->db->escape($this->email)."'";
$resql = $this->db->query($sql);
if ($resql) {
diff --git a/htdocs/contact/consumption.php b/htdocs/contact/consumption.php
index da00374cc2a..1e0f5b06094 100644
--- a/htdocs/contact/consumption.php
+++ b/htdocs/contact/consumption.php
@@ -37,8 +37,12 @@ $id = GETPOST('id', 'int');
$result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
$object = new Contact($db);
-if ($id > 0) $object->fetch($id);
-if (empty($object->thirdparty)) $object->fetch_thirdparty();
+if ($id > 0) {
+ $object->fetch($id);
+}
+if (empty($object->thirdparty)) {
+ $object->fetch_thirdparty();
+}
$socid = $object->thirdparty->id;
// Sort & Order fields
@@ -46,12 +50,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 = 'dateprint';
+if (!$sortorder) {
+ $sortorder = 'DESC';
+}
+if (!$sortfield) {
+ $sortfield = 'dateprint';
+}
// Search fields
$sref = GETPOST("sref");
@@ -60,8 +70,7 @@ $month = GETPOST('month', 'int');
$year = GETPOST('year', 'int');
// Clean up on purge search criteria ?
-if (GETPOST('button_removefilter_x', 'alpha') || 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.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
$sref = '';
$sprod_fulldescr = '';
$year = '';
@@ -84,7 +93,9 @@ $hookmanager->initHooks(array('consumptioncontact'));
$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');
+}
/*
@@ -99,8 +110,7 @@ $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("C
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('', $title, $help_url);
-if (empty($id))
-{
+if (empty($id)) {
dol_print_error($db);
exit;
}
@@ -111,13 +121,15 @@ print dol_get_fiche_head($head, 'consumption', $langs->trans("ContactsAddresses"
$linkback = '
'.$langs->trans("BackToList").' ';
$morehtmlref = '
';
-if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-{
+if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
$objsoc->fetch($socid);
// Thirdparty
$morehtmlref .= $langs->trans('ThirdParty').' : ';
- if ($objsoc->id > 0) $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
- else $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+ if ($objsoc->id > 0) {
+ $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
+ } else {
+ $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
+ }
}
$morehtmlref .= '
';
@@ -133,22 +145,34 @@ print '
'.$langs->trans("UserTitle").' ';
print $object->getCivilityLabel();
print ' ';
-if ($object->thirdparty->client)
-{
+if ($object->thirdparty->client) {
$thirdTypeArray['customer'] = $langs->trans("customer");
- if ($conf->propal->enabled && $user->rights->propal->lire) $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
- if ($conf->commande->enabled && $user->rights->commande->lire) $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
- if ($conf->facture->enabled && $user->rights->facture->lire) $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
- if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
+ if ($conf->propal->enabled && $user->rights->propal->lire) {
+ $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
+ }
+ if ($conf->commande->enabled && $user->rights->commande->lire) {
+ $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
+ }
+ if ($conf->facture->enabled && $user->rights->facture->lire) {
+ $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
+ }
+ if ($conf->contrat->enabled && $user->rights->contrat->lire) {
+ $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
+ }
}
-if ($conf->ficheinter->enabled && $user->rights->ficheinter->lire) $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
+if ($conf->ficheinter->enabled && $user->rights->ficheinter->lire) {
+ $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
+}
-if ($object->thirdparty->fournisseur)
-{
+if ($object->thirdparty->fournisseur) {
$thirdTypeArray['supplier'] = $langs->trans("supplier");
- if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
- if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) && $user->rights->fournisseur->commande->lire) $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
+ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) {
+ $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
+ }
+ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) && $user->rights->fournisseur->commande->lire) {
+ $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
+ }
// There no contact type for supplier proposals
// if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $user->rights->supplier_proposal->lire) $elementTypeArray['supplier_proposal']=$langs->transnoentitiesnoconv('SupplierProposals');
@@ -166,8 +190,7 @@ print '
';
+ }
} else {
dol_print_error($db);
}
@@ -797,15 +815,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 '';
}
- 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 ''.$langs->trans("AddSupplierProposal").' ';
@@ -814,8 +829,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 ''.$langs->trans("AddOrder").' ';
@@ -824,21 +838,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 '';
} else {
print '';
}
- } else print '';
+ } else {
+ print '';
+ }
}
- if ($user->rights->fournisseur->facture->creer)
- {
+ if ($user->rights->fournisseur->facture->creer) {
$langs->load("bills");
if ($object->status == 1) {
print ''.$langs->trans("AddBill").' ';
@@ -848,10 +861,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 ''.$langs->trans("AddAction").' ';
} else {
print ''.$langs->trans("AddAction").' ';
@@ -862,15 +873,13 @@ if ($object->id > 0)
print '';
- if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
- {
+ if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD)) {
print ' ';
// 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
diff --git a/htdocs/fourn/class/api_supplier_invoices.class.php b/htdocs/fourn/class/api_supplier_invoices.class.php
index 247434be7a8..953092120e4 100644
--- a/htdocs/fourn/class/api_supplier_invoices.class.php
+++ b/htdocs/fourn/class/api_supplier_invoices.class.php
@@ -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;
diff --git a/htdocs/fourn/class/api_supplier_orders.class.php b/htdocs/fourn/class/api_supplier_orders.class.php
index 254e577f2f2..895902b13b2 100644
--- a/htdocs/fourn/class/api_supplier_orders.class.php
+++ b/htdocs/fourn/class/api_supplier_orders.class.php
@@ -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;
diff --git a/htdocs/fourn/class/fournisseur.class.php b/htdocs/fourn/class/fournisseur.class.php
index 4ca073a38c7..57f6fa52d26 100644
--- a/htdocs/fourn/class/fournisseur.class.php
+++ b/htdocs/fourn/class/fournisseur.class.php
@@ -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 {
diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index 52121d8c83d..d4e92fd8bf4 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -34,7 +34,9 @@
include_once DOL_DOCUMENT_ROOT.'/core/class/commonorder.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
-if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
+if (!empty($conf->productbatch->enabled)) {
+ require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
+}
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
/**
@@ -303,7 +305,9 @@ class CommandeFournisseur extends CommonOrder
global $conf;
// Check parameters
- if (empty($id) && empty($ref)) return -1;
+ if (empty($id) && empty($ref)) {
+ return -1;
+ }
$sql = "SELECT c.rowid, c.entity, c.ref, ref_supplier, c.fk_soc, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.total_tva,";
$sql .= " c.localtax1, c.localtax2, ";
@@ -324,18 +328,21 @@ class CommandeFournisseur extends CommonOrder
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_input_method as cm ON cm.rowid = c.fk_input_method";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid';
- if (empty($id)) $sql .= " WHERE c.entity IN (".getEntity('supplier_order').")";
- else $sql .= " WHERE c.rowid=".$id;
+ if (empty($id)) {
+ $sql .= " WHERE c.entity IN (".getEntity('supplier_order').")";
+ } else {
+ $sql .= " WHERE c.rowid=".$id;
+ }
- if ($ref) $sql .= " AND c.ref='".$this->db->escape($ref)."'";
+ if ($ref) {
+ $sql .= " AND c.ref='".$this->db->escape($ref)."'";
+ }
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$obj = $this->db->fetch_object($resql);
- if (!$obj)
- {
+ if (!$obj) {
$this->error = 'Bill with id '.$id.' not found';
dol_syslog(get_class($this).'::fetch '.$this->error);
return 0;
@@ -409,14 +416,15 @@ class CommandeFournisseur extends CommonOrder
// fetch optionals attributes and labels
$this->fetch_optionals();
- if ($this->statut == 0) $this->brouillon = 1;
+ if ($this->statut == 0) {
+ $this->brouillon = 1;
+ }
/*
- * Lines
- */
+ * Lines
+ */
$result = $this->fetch_lines();
- if ($result < 0)
- {
+ if ($result < 0) {
return -1;
} else {
return 1;
@@ -449,26 +457,28 @@ class CommandeFournisseur extends CommonOrder
$sql .= " l.fk_unit,";
$sql .= " l.date_start, l.date_end,";
$sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
+ if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$sql .= ", pfp.rowid as fk_pfp, pfp.packaging";
+ }
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
+ if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON l.fk_product = pfp.fk_product and l.ref = pfp.ref_fourn";
+ }
$sql .= " WHERE l.fk_commande = ".$this->id;
- if ($only_product) $sql .= ' AND p.fk_product_type = 0';
+ if ($only_product) {
+ $sql .= ' AND p.fk_product_type = 0';
+ }
$sql .= " ORDER BY l.rang, l.rowid";
//print $sql;
dol_syslog(get_class($this)."::fetch get lines", LOG_DEBUG);
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$num = $this->db->num_rows($result);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$objp = $this->db->fetch_object($result);
$line = new CommandeFournisseurLigne($this->db);
@@ -505,8 +515,7 @@ class CommandeFournisseur extends CommonOrder
$line->ref_fourn = $objp->ref_supplier; // The supplier ref of price when product was added. May have change since
$line->ref_supplier = $objp->ref_supplier; // The supplier ref of price when product was added. May have change since
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
- {
+ if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$line->fk_fournprice = $objp->fk_pfp;
$line->packaging = $objp->packaging;
}
@@ -563,8 +572,7 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(get_class($this)."::valid");
$result = 0;
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->commande->creer))
- || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_order_advance->validate)))
- {
+ || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_order_advance->validate))) {
$this->db->begin();
// Definition of supplier order numbering model name
@@ -572,8 +580,7 @@ class CommandeFournisseur extends CommonOrder
$soc->fetch($this->fourn_id);
// Check if object has a temporary ref
- if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life
- {
+ if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
$num = $this->getNextNumRef($soc);
} else {
$num = $this->ref;
@@ -589,49 +596,46 @@ class CommandeFournisseur extends CommonOrder
$sql .= " AND fk_statut = ".self::STATUS_DRAFT;
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
dol_print_error($this->db);
$error++;
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('ORDER_SUPPLIER_VALIDATE', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->oldref = $this->ref;
// Rename directory if dir was a temporary ref
- if (preg_match('/^[\(]?PROV/i', $this->ref))
- {
+ if (preg_match('/^[\(]?PROV/i', $this->ref)) {
// Now we rename also files into index
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'fournisseur/commande/".$this->db->escape($this->newref)."'";
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
$resql = $this->db->query($sql);
- if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
+ if (!$resql) {
+ $error++; $this->error = $this->db->lasterror();
+ }
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
$oldref = dol_sanitizeFileName($this->ref);
$newref = dol_sanitizeFileName($num);
$dirsource = $conf->fournisseur->commande->dir_output.'/'.$oldref;
$dirdest = $conf->fournisseur->commande->dir_output.'/'.$newref;
- if (!$error && file_exists($dirsource))
- {
+ if (!$error && file_exists($dirsource)) {
dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest);
- if (@rename($dirsource, $dirdest))
- {
+ if (@rename($dirsource, $dirdest)) {
dol_syslog("Rename ok");
// Rename docs starting with $oldref with $newref
$listoffiles = dol_dir_list($conf->fournisseur->commande->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
- foreach ($listoffiles as $fileentry)
- {
+ foreach ($listoffiles as $fileentry) {
$dirsource = $fileentry['name'];
$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
$dirsource = $fileentry['path'].'/'.$dirsource;
@@ -643,15 +647,13 @@ class CommandeFournisseur extends CommonOrder
}
}
- if (!$error)
- {
+ if (!$error) {
$result = 1;
$this->statut = self::STATUS_VALIDATED;
$this->ref = $num;
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
@@ -696,8 +698,11 @@ class CommandeFournisseur extends CommonOrder
$this->statuts[0] = 'StatusSupplierOrderDraft';
$this->statuts[1] = 'StatusSupplierOrderValidated';
$this->statuts[2] = 'StatusSupplierOrderApproved';
- if (empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) $this->statuts[3] = 'StatusSupplierOrderOnProcess';
- else $this->statuts[3] = 'StatusSupplierOrderOnProcessWithValidation';
+ if (empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
+ $this->statuts[3] = 'StatusSupplierOrderOnProcess';
+ } else {
+ $this->statuts[3] = 'StatusSupplierOrderOnProcessWithValidation';
+ }
$this->statuts[4] = 'StatusSupplierOrderReceivedPartially';
$this->statuts[5] = 'StatusSupplierOrderReceivedAll';
$this->statuts[6] = 'StatusSupplierOrderCanceled'; // Approved->Canceled
@@ -737,7 +742,9 @@ class CommandeFournisseur extends CommonOrder
if ($billed) {
$billedtext = ' - '.$langs->trans("Billed");
}
- if ($status == 5 && $billed) $statusClass = 'status6';
+ if ($status == 5 && $billed) {
+ $statusClass = 'status6';
+ }
$statusLong = $langs->transnoentitiesnoconv($this->statuts[$status]).$billedtext;
$statusShort = $langs->transnoentitiesnoconv($this->statutshort[$status]);
@@ -792,19 +799,20 @@ class CommandeFournisseur extends CommonOrder
$picto = 'order';
$url = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$this->id;
- if ($option !== 'nolink')
- {
+ if ($option !== 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
- if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
- if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
}
$linkclose = '';
- if (empty($notooltip))
- {
- if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
- {
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowOrder");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
@@ -817,15 +825,17 @@ class CommandeFournisseur extends CommonOrder
$linkend = '';
$result .= $linkstart;
- if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($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, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ if ($withpicto != 2) {
+ $result .= $this->ref;
+ }
$result .= $linkend;
- if ($addlinktonotes)
- {
+ if ($addlinktonotes) {
$txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
- if ($txttoshow)
- {
+ if ($txttoshow) {
$notetoshow = $langs->trans("ViewPrivateNote").': '.dol_string_nohtmltag($txttoshow, 1);
$result .= ' ';
$result .= '';
@@ -853,8 +863,7 @@ class CommandeFournisseur extends CommonOrder
global $db, $langs, $conf;
$langs->load("orders");
- if (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER))
- {
+ if (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER)) {
$mybool = false;
$file = $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER.'.php';
@@ -878,8 +887,7 @@ class CommandeFournisseur extends CommonOrder
$obj = new $classname();
$numref = $obj->getNextValue($soc, $this);
- if ($numref != "")
- {
+ if ($numref != "") {
return $numref;
} else {
$this->error = $obj->error;
@@ -900,8 +908,7 @@ class CommandeFournisseur extends CommonOrder
{
$error = 0;
- if ($this->billed)
- {
+ if ($this->billed) {
return 0;
}
@@ -910,18 +917,17 @@ class CommandeFournisseur extends CommonOrder
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur SET billed = 1';
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT;
- if ($this->db->query($sql))
- {
- if (!$error)
- {
+ if ($this->db->query($sql)) {
+ if (!$error) {
// Call trigger
$result = $this->call_trigger('ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->billed = 1;
$this->db->commit();
@@ -955,8 +961,7 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(get_class($this)."::approve");
- if ($user->rights->fournisseur->commande->approuver)
- {
+ if ($user->rights->fournisseur->commande->approuver) {
$now = dol_now();
$this->db->begin();
@@ -966,8 +971,7 @@ class CommandeFournisseur extends CommonOrder
$soc->fetch($this->fourn_id);
// Check if object has a temporary ref
- if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life
- {
+ if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
$num = $this->getNextNumRef($soc);
} else {
$num = $this->ref;
@@ -980,14 +984,11 @@ class CommandeFournisseur extends CommonOrder
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
$sql .= " SET ref='".$this->db->escape($num)."',";
- if (empty($secondlevel)) // standard or first level approval
- {
+ if (empty($secondlevel)) { // standard or first level approval
$sql .= " date_approve='".$this->db->idate($now)."',";
$sql .= " fk_user_approve = ".$user->id;
- if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $conf->global->MAIN_FEATURES_LEVEL > 0 && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)
- {
- if (empty($this->user_approve_id2))
- {
+ if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $conf->global->MAIN_FEATURES_LEVEL > 0 && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
+ if (empty($this->user_approve_id2)) {
$movetoapprovestatus = false; // second level approval not done
$comment = ' (first level)';
}
@@ -996,67 +997,72 @@ class CommandeFournisseur extends CommonOrder
{
$sql .= " date_approve2='".$this->db->idate($now)."',";
$sql .= " fk_user_approve2 = ".$user->id;
- if (empty($this->user_approve_id)) $movetoapprovestatus = false; // first level approval not done
+ if (empty($this->user_approve_id)) {
+ $movetoapprovestatus = false; // first level approval not done
+ }
$comment = ' (second level)';
}
// If double approval is required and first approval, we keep status to 1 = validated
- if ($movetoapprovestatus) $sql .= ", fk_statut = ".self::STATUS_ACCEPTED;
- else $sql .= ", fk_statut = ".self::STATUS_VALIDATED;
+ if ($movetoapprovestatus) {
+ $sql .= ", fk_statut = ".self::STATUS_ACCEPTED;
+ } else {
+ $sql .= ", fk_statut = ".self::STATUS_VALIDATED;
+ }
$sql .= " WHERE rowid = ".$this->id;
$sql .= " AND fk_statut = ".self::STATUS_VALIDATED;
- if ($this->db->query($sql))
- {
- if (!empty($conf->global->SUPPLIER_ORDER_AUTOADD_USER_CONTACT))
- {
+ if ($this->db->query($sql)) {
+ if (!empty($conf->global->SUPPLIER_ORDER_AUTOADD_USER_CONTACT)) {
$result = $this->add_contact($user->id, 'SALESREPFOLL', 'internal', 1);
- if ($result < 0 && $result != -2) // -2 means already exists
- {
+ if ($result < 0 && $result != -2) { // -2 means already exists
$error++;
}
}
// If stock is incremented on validate order, we must increment it
- if (!$error && $movetoapprovestatus && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER))
- {
+ if (!$error && $movetoapprovestatus && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) {
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
$langs->load("agenda");
$cpt = count($this->lines);
- for ($i = 0; $i < $cpt; $i++)
- {
+ for ($i = 0; $i < $cpt; $i++) {
// Product with reference
- if ($this->lines[$i]->fk_product > 0)
- {
+ if ($this->lines[$i]->fk_product > 0) {
$this->line = $this->lines[$i];
$mouvP = new MouvementStock($this->db);
$mouvP->origin = &$this;
// We decrement stock of product (and sub-products)
$up_ht_disc = $this->lines[$i]->subprice;
- if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc = price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU');
+ if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) {
+ $up_ht_disc = price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU');
+ }
$result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("OrderApprovedInDolibarr", $this->ref));
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
unset($this->line);
}
}
}
- if (!$error)
- {
+ if (!$error) {
// Call trigger
$result = $this->call_trigger('ORDER_SUPPLIER_APPROVE', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->ref = $this->newref;
- if ($movetoapprovestatus) $this->statut = self::STATUS_ACCEPTED;
- else $this->statut = self::STATUS_VALIDATED;
- if (empty($secondlevel)) // standard or first level approval
- {
+ if ($movetoapprovestatus) {
+ $this->statut = self::STATUS_ACCEPTED;
+ } else {
+ $this->statut = self::STATUS_VALIDATED;
+ }
+ if (empty($secondlevel)) { // standard or first level approval
$this->date_approve = $now;
$this->user_approve_id = $user->id;
} else // request a second level approval
@@ -1096,26 +1102,24 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(get_class($this)."::refuse");
$result = 0;
- if ($user->rights->fournisseur->commande->approuver)
- {
+ if ($user->rights->fournisseur->commande->approuver) {
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = ".self::STATUS_REFUSED;
$sql .= " WHERE rowid = ".$this->id;
- if ($this->db->query($sql))
- {
+ if ($this->db->query($sql)) {
$result = 0;
- if ($error == 0)
- {
+ if ($error == 0) {
// Call trigger
$result = $this->call_trigger('ORDER_SUPPLIER_REFUSE', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
$this->db->rollback();
- } else $this->db->commit();
+ } else {
+ $this->db->commit();
+ }
// End call triggers
}
} else {
@@ -1148,8 +1152,7 @@ class CommandeFournisseur extends CommonOrder
//dol_syslog("CommandeFournisseur::Cancel");
$result = 0;
- if ($user->rights->fournisseur->commande->commander)
- {
+ if ($user->rights->fournisseur->commande->commander) {
$statut = self::STATUS_CANCELED;
$this->db->begin();
@@ -1157,17 +1160,17 @@ class CommandeFournisseur extends CommonOrder
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = ".$statut;
$sql .= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::cancel", LOG_DEBUG);
- if ($this->db->query($sql))
- {
+ if ($this->db->query($sql)) {
$result = 0;
// Call trigger
$result = $this->call_trigger('ORDER_SUPPLIER_CANCEL', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
- if ($error == 0)
- {
+ if ($error == 0) {
$this->db->commit();
return 1;
} else {
@@ -1200,12 +1203,13 @@ class CommandeFournisseur extends CommonOrder
global $langs;
dol_syslog(get_class($this)."::commande");
$error = 0;
- if ($user->rights->fournisseur->commande->commander)
- {
+ if ($user->rights->fournisseur->commande->commander) {
$this->db->begin();
$newnoteprivate = $this->note_private;
- if ($comment) $newnoteprivate = dol_concatdesc($newnoteprivate, $langs->trans("Comment").': '.$comment);
+ if ($comment) {
+ $newnoteprivate = dol_concatdesc($newnoteprivate, $langs->trans("Comment").': '.$comment);
+ }
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
$sql .= " SET fk_statut=".self::STATUS_ORDERSENT.", fk_input_method=".$methode.", date_commande='".$this->db->idate($date)."', ";
@@ -1213,8 +1217,7 @@ class CommandeFournisseur extends CommonOrder
$sql .= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::commande", LOG_DEBUG);
- if ($this->db->query($sql))
- {
+ if ($this->db->query($sql)) {
$this->statut = self::STATUS_ORDERSENT;
$this->methode_commande_id = $methode;
$this->date_commande = $date;
@@ -1222,7 +1225,9 @@ class CommandeFournisseur extends CommonOrder
// Call trigger
$result = $this->call_trigger('ORDER_SUPPLIER_SUBMIT', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
} else {
$error++;
@@ -1230,8 +1235,7 @@ class CommandeFournisseur extends CommonOrder
$this->errors[] = $this->db->lasterror();
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
} else {
$this->db->rollback();
@@ -1264,17 +1268,23 @@ class CommandeFournisseur extends CommonOrder
// set tmp vars
$date = ($this->date_commande ? $this->date_commande : $this->date); // in case of date is set
- if (empty($date)) $date = $now;
+ if (empty($date)) {
+ $date = $now;
+ }
$delivery_date = empty($this->delivery_date) ? $this->date_livraison : $this->delivery_date;
// Clean parameters
- if (empty($this->source)) $this->source = 0;
+ if (empty($this->source)) {
+ $this->source = 0;
+ }
// Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if not using origin rate)
- if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $date);
- else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
- if (empty($this->fk_multicurrency))
- {
+ if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
+ list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $date);
+ } else {
+ $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
+ }
+ if (empty($this->fk_multicurrency)) {
$this->multicurrency_code = $conf->currency;
$this->fk_multicurrency = 0;
$this->multicurrency_tx = 1;
@@ -1330,16 +1340,14 @@ class CommandeFournisseur extends CommonOrder
$sql .= ")";
dol_syslog(get_class($this)."::create", LOG_DEBUG);
- if ($this->db->query($sql))
- {
+ if ($this->db->query($sql)) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur");
if ($this->id) {
$num = count($this->lines);
// insert products details into database
- for ($i = 0; $i < $num; $i++)
- {
+ for ($i = 0; $i < $num; $i++) {
$this->special_code = $this->lines[$i]->special_code; // TODO : remove this in 9.0 and add special_code param to addline()
// This include test on qty if option SUPPLIER_ORDER_WITH_NOPRICEDEFINED is not set
@@ -1364,8 +1372,7 @@ class CommandeFournisseur extends CommonOrder
$this->lines[$i]->array_options,
$this->lines[$i]->fk_unit
);
- if ($result < 0)
- {
+ if ($result < 0) {
dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING); // do not use dol_print_error here as it may be a functionnal error
$this->db->rollback();
return -1;
@@ -1376,30 +1383,22 @@ class CommandeFournisseur extends CommonOrder
$sql .= " SET ref='(PROV".$this->id.")'";
$sql .= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::create", LOG_DEBUG);
- if ($this->db->query($sql))
- {
+ if ($this->db->query($sql)) {
// Add link with price request and supplier order
- if ($this->id)
- {
+ if ($this->id) {
$this->ref = "(PROV".$this->id.")";
- if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects
- {
+ if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
$this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
}
// Add object linked
- if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects))
- {
- foreach ($this->linked_objects as $origin => $tmp_origin_id)
- {
- if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
- {
- foreach ($tmp_origin_id as $origin_id)
- {
+ if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
+ foreach ($this->linked_objects as $origin => $tmp_origin_id) {
+ if (is_array($tmp_origin_id)) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
+ foreach ($tmp_origin_id as $origin_id) {
$ret = $this->add_object_linked($origin, $origin_id);
- if (!$ret)
- {
+ if (!$ret) {
dol_print_error($this->db);
$error++;
}
@@ -1408,8 +1407,7 @@ class CommandeFournisseur extends CommonOrder
{
$origin_id = $tmp_origin_id;
$ret = $this->add_object_linked($origin, $origin_id);
- if (!$ret)
- {
+ if (!$ret) {
dol_print_error($this->db);
$error++;
}
@@ -1418,18 +1416,17 @@ class CommandeFournisseur extends CommonOrder
}
}
- if (!$error)
- {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('ORDER_SUPPLIER_CREATE', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->db->rollback();
return -1;
}
@@ -1467,19 +1464,18 @@ class CommandeFournisseur extends CommonOrder
$this->db->begin();
// get extrafields so they will be clone
- foreach ($this->lines as $line)
+ foreach ($this->lines as $line) {
$line->fetch_optionals();
+ }
// Load source object
$objFrom = clone $this;
// Change socid if needed
- if (!empty($socid) && $socid != $this->socid)
- {
+ if (!empty($socid) && $socid != $this->socid) {
$objsoc = new Societe($this->db);
- if ($objsoc->fetch($socid) > 0)
- {
+ if ($objsoc->fetch($socid) > 0) {
$this->socid = $objsoc->id;
$this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
$this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
@@ -1507,25 +1503,26 @@ class CommandeFournisseur extends CommonOrder
// Create clone
$this->context['createfromclone'] = 'createfromclone';
$result = $this->create($user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
- if (!$error)
- {
+ if (!$error) {
// Hook of thirdparty module
- if (is_object($hookmanager))
- {
+ if (is_object($hookmanager)) {
$parameters = array('objFrom'=>$objFrom);
$action = '';
$reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
- if ($reshook < 0) $error++;
+ if ($reshook < 0) {
+ $error++;
+ }
}
}
unset($this->context['createfromclone']);
// End
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return $this->id;
} else {
@@ -1568,17 +1565,28 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $fk_prod_fourn_price, $ref_supplier, $remise_percent, $price_base_type, $pu_ttc, $type, $info_bits, $notrigger, $date_start, $date_end, $fk_unit, $pu_ht_devise, $origin, $origin_id");
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
- if ($this->statut == self::STATUS_DRAFT)
- {
+ if ($this->statut == self::STATUS_DRAFT) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Clean parameters
- if (empty($qty)) $qty = 0;
- if (!$info_bits) $info_bits = 0;
- if (empty($txtva)) $txtva = 0;
- if (empty($txlocaltax1)) $txlocaltax1 = 0;
- if (empty($txlocaltax2)) $txlocaltax2 = 0;
- if (empty($remise_percent)) $remise_percent = 0;
+ if (empty($qty)) {
+ $qty = 0;
+ }
+ if (!$info_bits) {
+ $info_bits = 0;
+ }
+ if (empty($txtva)) {
+ $txtva = 0;
+ }
+ if (empty($txlocaltax1)) {
+ $txlocaltax1 = 0;
+ }
+ if (empty($txlocaltax2)) {
+ $txlocaltax2 = 0;
+ }
+ if (empty($remise_percent)) {
+ $remise_percent = 0;
+ }
$remise_percent = price2num($remise_percent);
$qty = price2num($qty);
@@ -1590,8 +1598,7 @@ class CommandeFournisseur extends CommonOrder
}
$txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2);
- if ($price_base_type == 'HT')
- {
+ if ($price_base_type == 'HT') {
$pu = $pu_ht;
} else {
$pu = $pu_ttc;
@@ -1599,12 +1606,13 @@ class CommandeFournisseur extends CommonOrder
$desc = trim($desc);
// Check parameters
- if ($qty < 0 && !$fk_product)
- {
+ if ($qty < 0 && !$fk_product) {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product"));
return -1;
}
- if ($type < 0) return -1;
+ if ($type < 0) {
+ return -1;
+ }
if ($date_start && $date_end && $date_start > $date_end) {
$langs->load("errors");
$this->error = $langs->trans('ErrorStartDateGreaterEnd');
@@ -1632,15 +1640,15 @@ class CommandeFournisseur extends CommonOrder
// If supplier order created from customer order, we take best supplier price
// If $pu (defined previously from pu_ht or pu_ttc) is not defined at all, we also take the best supplier price
- if ($result > 0 && ($origin == 'commande' || $pu === ''))
- {
+ if ($result > 0 && ($origin == 'commande' || $pu === '')) {
$pu = $prod->fourn_pu; // Unit price supplier price set by get_buyprice
$ref_supplier = $prod->ref_supplier; // Ref supplier price set by get_buyprice
// is remise percent not keyed but present for the product we add it
- if ($remise_percent == 0 && $prod->remise_percent != 0) $remise_percent = $prod->remise_percent;
+ if ($remise_percent == 0 && $prod->remise_percent != 0) {
+ $remise_percent = $prod->remise_percent;
+ }
}
- if ($result == 0) // If result == 0, we failed to found the supplier reference price
- {
+ if ($result == 0) { // If result == 0, we failed to found the supplier reference price
$langs->load("errors");
$this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
$this->db->rollback();
@@ -1649,16 +1657,14 @@ class CommandeFournisseur extends CommonOrder
//$ref = $prod->ref_fourn; // We do not overwrite ref supplier price
return -1;
}
- if ($result == -1)
- {
+ if ($result == -1) {
$langs->load("errors");
$this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
$this->db->rollback();
dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_DEBUG);
return -1;
}
- if ($result < -1)
- {
+ if ($result < -1) {
$this->error = $prod->error;
$this->db->rollback();
dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_ERR);
@@ -1695,8 +1701,7 @@ class CommandeFournisseur extends CommonOrder
// Clean vat code
$vat_src_code = '';
- if (preg_match('/\((.*)\)/', $txtva, $reg))
- {
+ if (preg_match('/\((.*)\)/', $txtva, $reg)) {
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
@@ -1783,15 +1788,15 @@ class CommandeFournisseur extends CommonOrder
}
$result = $this->line->insert($notrigger);
- if ($result > 0)
- {
+ if ($result > 0) {
// Reorder if child line
- if (!empty($fk_parent_line)) $this->line_order(true, 'DESC');
+ if (!empty($fk_parent_line)) {
+ $this->line_order(true, 'DESC');
+ }
// Mise a jour informations denormalisees au niveau de la commande meme
$result = $this->update_price(1, 'auto', 0, $this->thirdparty); // This method is designed to add line from user input so total calculation must be done using 'auto' mode.
- if ($result > 0)
- {
+ if ($result > 0) {
$this->db->commit();
return $this->line->id;
} else {
@@ -1833,24 +1838,23 @@ class CommandeFournisseur extends CommonOrder
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
// Check parameters (if test are wrong here, there is bug into caller)
- if ($entrepot <= 0)
- {
+ if ($entrepot <= 0) {
$this->error = 'ErrorBadValueForParameterWarehouse';
return -1;
}
- if ($qty == 0)
- {
+ if ($qty == 0) {
$this->error = 'ErrorBadValueForParameterQty';
return -1;
}
$dispatchstatus = 1;
- if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) $dispatchstatus = 0; // Setting dispatch status (a validation step after receiving products) will be done manually to 1 or 2 if this option is on
+ if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
+ $dispatchstatus = 0; // Setting dispatch status (a validation step after receiving products) will be done manually to 1 or 2 if this option is on
+ }
$now = dol_now();
- if (($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY || $this->statut == self::STATUS_RECEIVED_COMPLETELY))
- {
+ if (($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY || $this->statut == self::STATUS_RECEIVED_COMPLETELY)) {
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_dispatch";
@@ -1861,15 +1865,12 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(get_class($this)."::dispatchProduct", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
- if (!$notrigger)
- {
+ if ($resql) {
+ if (!$notrigger) {
global $conf, $langs, $user;
// Call trigger
$result = $this->call_trigger('LINEORDER_SUPPLIER_DISPATCH', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
// End call triggers
@@ -1880,16 +1881,13 @@ class CommandeFournisseur extends CommonOrder
}
// If module stock is enabled and the stock increase is done on purchase order dispatching
- if (!$error && $entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER))
- {
+ if (!$error && $entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
$mouv = new MouvementStock($this->db);
- if ($product > 0)
- {
+ if ($product > 0) {
// $price should take into account discount (except if option STOCK_EXCLUDE_DISCOUNT_FOR_PMP is on)
$mouv->origin = &$this;
$result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $mouv->error;
$this->errors = $mouv->errors;
dol_syslog(get_class($this)."::dispatchProduct ".$this->error." ".join(',', $this->errors), LOG_ERR);
@@ -1898,8 +1896,7 @@ class CommandeFournisseur extends CommonOrder
}
}
- if ($error == 0)
- {
+ if ($error == 0) {
$this->db->commit();
return 1;
} else {
@@ -1921,17 +1918,14 @@ class CommandeFournisseur extends CommonOrder
*/
public function deleteline($idline, $notrigger = 0)
{
- if ($this->statut == 0)
- {
+ if ($this->statut == 0) {
$line = new CommandeFournisseurLigne($this->db);
- if ($line->fetch($idline) <= 0)
- {
+ if ($line->fetch($idline) <= 0) {
return 0;
}
- if ($line->delete($notrigger) > 0)
- {
+ if ($line->delete($notrigger) > 0) {
$this->update_price();
return 1;
} else {
@@ -1960,12 +1954,10 @@ class CommandeFournisseur extends CommonOrder
$this->db->begin();
- if (empty($notrigger))
- {
+ if (empty($notrigger)) {
// Call trigger
$result = $this->call_trigger('ORDER_SUPPLIER_DELETE', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->errors[] = 'ErrorWhenRunningTrigger';
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
$this->db->rollback();
@@ -1978,8 +1970,7 @@ class CommandeFournisseur extends CommonOrder
$ef = $main."_extrafields";
$sql = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".$this->id.")";
dol_syslog(get_class($this)."::delete extrafields lines", LOG_DEBUG);
- if (!$this->db->query($sql))
- {
+ if (!$this->db->query($sql)) {
$this->error = $this->db->lasterror();
$this->errors[] = $this->db->lasterror();
$error++;
@@ -1987,8 +1978,7 @@ class CommandeFournisseur extends CommonOrder
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE fk_commande =".$this->id;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
- if (!$this->db->query($sql))
- {
+ if (!$this->db->query($sql)) {
$this->error = $this->db->lasterror();
$this->errors[] = $this->db->lasterror();
$error++;
@@ -1996,10 +1986,8 @@ class CommandeFournisseur extends CommonOrder
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE rowid =".$this->id;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
- if ($resql = $this->db->query($sql))
- {
- if ($this->db->affected_rows($resql) < 1)
- {
+ if ($resql = $this->db->query($sql)) {
+ if ($this->db->affected_rows($resql) < 1) {
$this->error = $this->db->lasterror();
$this->errors[] = $this->db->lasterror();
$error++;
@@ -2011,11 +1999,9 @@ class CommandeFournisseur extends CommonOrder
}
// Remove extrafields
- if (!$error)
- {
+ if (!$error) {
$result = $this->deleteExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = 'FailToDeleteExtraFields';
$this->errors[] = 'FailToDeleteExtraFields';
$error++;
@@ -2031,31 +2017,25 @@ class CommandeFournisseur extends CommonOrder
$error++;
}
- if (!$error)
- {
+ if (!$error) {
// Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive
$this->deleteEcmFiles();
// We remove directory
$ref = dol_sanitizeFileName($this->ref);
- if ($conf->fournisseur->commande->dir_output)
- {
+ if ($conf->fournisseur->commande->dir_output) {
$dir = $conf->fournisseur->commande->dir_output."/".$ref;
$file = $dir."/".$ref.".pdf";
- if (file_exists($file))
- {
- if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers
- {
+ if (file_exists($file)) {
+ if (!dol_delete_file($file, 0, 0, 0, $this)) { // For triggers
$this->error = 'ErrorFailToDeleteFile';
$this->errors[] = 'ErrorFailToDeleteFile';
$error++;
}
}
- if (file_exists($dir))
- {
+ if (file_exists($dir)) {
$res = @dol_delete_dir_recursive($dir);
- if (!$res)
- {
+ if (!$res) {
$this->error = 'ErrorFailToDeleteDir';
$this->errors[] = 'ErrorFailToDeleteDir';
$error++;
@@ -2064,8 +2044,7 @@ class CommandeFournisseur extends CommonOrder
}
}
- if (!$error)
- {
+ if (!$error) {
dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG);
$this->db->commit();
return 1;
@@ -2090,13 +2069,11 @@ class CommandeFournisseur extends CommonOrder
$sql .= " WHERE active = 1";
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $this->db->num_rows($resql);
$this->methodes_commande = array();
- while ($i < $num)
- {
+ while ($i < $num) {
$row = $this->db->fetch_row($resql);
$this->methodes_commande[$row[0]] = $row[1];
@@ -2130,20 +2107,19 @@ class CommandeFournisseur extends CommonOrder
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid";
$sql .= " WHERE cfd.fk_commande = ".$this->id;
$sql .= " AND cfd.fk_product = p.rowid";
- if ($status >= 0) $sql .= " AND cfd.status = ".$status;
+ if ($status >= 0) {
+ $sql .= " AND cfd.status = ".$status;
+ }
$sql .= " ORDER BY cfd.rowid ASC";
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$objp = $this->db->fetch_object($resql);
- if ($objp)
- {
+ if ($objp) {
$ret[] = array(
'id' => $objp->dispatchedlineid,
'productid' => $objp->fk_product,
@@ -2154,7 +2130,9 @@ class CommandeFournisseur extends CommonOrder
$i++;
}
- } else dol_print_error($this->db, 'Failed to execute request to get dispatched lines');
+ } else {
+ dol_print_error($this->db, 'Failed to execute request to get dispatched lines');
+ }
return $ret;
}
@@ -2180,39 +2158,37 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(get_class($this)."::Livraison");
- if ($user->rights->fournisseur->commande->receptionner)
- {
+ if ($user->rights->fournisseur->commande->receptionner) {
// Define the new status
- if ($type == 'par') $statut = self::STATUS_RECEIVED_PARTIALLY;
- elseif ($type == 'tot') $statut = self::STATUS_RECEIVED_COMPLETELY;
- elseif ($type == 'nev') $statut = self::STATUS_CANCELED_AFTER_ORDER;
- elseif ($type == 'can') $statut = self::STATUS_CANCELED_AFTER_ORDER;
- else {
+ if ($type == 'par') {
+ $statut = self::STATUS_RECEIVED_PARTIALLY;
+ } elseif ($type == 'tot') {
+ $statut = self::STATUS_RECEIVED_COMPLETELY;
+ } elseif ($type == 'nev') {
+ $statut = self::STATUS_CANCELED_AFTER_ORDER;
+ } elseif ($type == 'can') {
+ $statut = self::STATUS_CANCELED_AFTER_ORDER;
+ } else {
$error++;
dol_syslog(get_class($this)."::Livraison Error -2", LOG_ERR);
return -2;
}
// Some checks to accept the record
- if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS))
- {
+ if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
// If option SUPPLIER_ORDER_USE_DISPATCH_STATUS is on, we check all reception are approved to allow status "total/done"
- if (!$error && ($type == 'tot'))
- {
+ if (!$error && ($type == 'tot')) {
$dispatchedlinearray = $this->getDispachedLines(0);
- if (count($dispatchedlinearray) > 0)
- {
+ if (count($dispatchedlinearray) > 0) {
$result = -1;
$error++;
$this->errors[] = 'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
dol_syslog('ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
}
}
- if (!$error && !empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE) && ($type == 'tot')) // Accept to move to reception done, only if status of all line are ok (refuse denied)
- {
+ if (!$error && !empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE) && ($type == 'tot')) { // Accept to move to reception done, only if status of all line are ok (refuse denied)
$dispatcheddenied = $this->getDispachedLines(2);
- if (count($dispatchedlinearray) > 0)
- {
+ if (count($dispatchedlinearray) > 0) {
$result = -1;
$error++;
$this->errors[] = 'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
@@ -2223,8 +2199,7 @@ class CommandeFournisseur extends CommonOrder
// TODO LDR01 Add a control test to accept only if ALL predefined products are received (same qty).
- if (empty($error))
- {
+ if (empty($error)) {
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
@@ -2234,8 +2209,7 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(get_class($this)."::Livraison", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$result = 1;
$old_statut = $this->statut;
$this->statut = $statut;
@@ -2243,11 +2217,12 @@ class CommandeFournisseur extends CommonOrder
// Call trigger
$result_trigger = $this->call_trigger('ORDER_SUPPLIER_RECEIVE', $user);
- if ($result_trigger < 0) $error++;
+ if ($result_trigger < 0) {
+ $error++;
+ }
// End call triggers
- if (empty($error))
- {
+ if (empty($error)) {
$this->db->commit();
} else {
$this->statut = $old_statut;
@@ -2296,8 +2271,7 @@ class CommandeFournisseur extends CommonOrder
*/
public function setDeliveryDate($user, $delivery_date, $notrigger = 0)
{
- if ($user->rights->fournisseur->commande->creer)
- {
+ if ($user->rights->fournisseur->commande->creer) {
$error = 0;
$this->db->begin();
@@ -2308,34 +2282,31 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->date_livraison = $delivery_date;
$this->delivery_date = $delivery_date;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('ORDER_SUPPLIER_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2359,8 +2330,7 @@ class CommandeFournisseur extends CommonOrder
public function set_id_projet($user, $id_projet, $notrigger = 0)
{
// phpcs:enable
- if ($user->rights->fournisseur->commande->creer)
- {
+ if ($user->rights->fournisseur->commande->creer) {
$error = 0;
$this->db->begin();
@@ -2371,34 +2341,31 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->fk_projet = $id_projet;
$this->fk_project = $id_projet;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('ORDER_SUPPLIER_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2428,13 +2395,11 @@ class CommandeFournisseur extends CommonOrder
$this->lines = array();
$num = count($comclient->lines);
- for ($i = 0; $i < $num; $i++)
- {
+ for ($i = 0; $i < $num; $i++) {
$prod = new Product($this->db);
$label = '';
$ref = '';
- if ($prod->fetch($comclient->lines[$i]->fk_product) > 0)
- {
+ if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
$label = $prod->label;
$ref = $prod->ref;
}
@@ -2445,8 +2410,7 @@ class CommandeFournisseur extends CommonOrder
$sql .= ",".$comclient->lines[$i]->fk_product.", ".price2num($comclient->lines[$i]->price);
$sql .= ", ".$comclient->lines[$i]->qty.", ".$comclient->lines[$i]->tva_tx.", ".$comclient->lines[$i]->localtax1_tx.", ".$comclient->lines[$i]->localtax2_tx.", ".$comclient->lines[$i]->remise_percent;
$sql .= ", '".price2num($comclient->lines[$i]->subprice)."','0', '".$this->db->escape($ref)."');";
- if ($this->db->query($sql))
- {
+ if ($this->db->query($sql)) {
$this->update_price();
}
}
@@ -2474,8 +2438,7 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(get_class($this)."::setStatus", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
// Trigger names for each status
$triggerName = array();
$triggerName[0] = 'DRAFT';
@@ -2490,7 +2453,9 @@ class CommandeFournisseur extends CommonOrder
// Call trigger
$result = $this->call_trigger("ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
} else {
$error++;
@@ -2498,8 +2463,7 @@ class CommandeFournisseur extends CommonOrder
dol_syslog(get_class($this)."::setStatus ".$this->error);
}
- if (!$error)
- {
+ if (!$error) {
$this->statut = $status;
$this->db->commit();
return 1;
@@ -2540,30 +2504,47 @@ class CommandeFournisseur extends CommonOrder
$error = 0;
- if ($this->brouillon)
- {
+ if ($this->brouillon) {
// Clean parameters
- if (empty($qty)) $qty = 0;
- if (empty($info_bits)) $info_bits = 0;
- if (empty($txtva)) $txtva = 0;
- if (empty($txlocaltax1)) $txlocaltax1 = 0;
- if (empty($txlocaltax2)) $txlocaltax2 = 0;
- if (empty($remise)) $remise = 0;
- if (empty($remise_percent)) $remise_percent = 0;
+ if (empty($qty)) {
+ $qty = 0;
+ }
+ if (empty($info_bits)) {
+ $info_bits = 0;
+ }
+ if (empty($txtva)) {
+ $txtva = 0;
+ }
+ if (empty($txlocaltax1)) {
+ $txlocaltax1 = 0;
+ }
+ if (empty($txlocaltax2)) {
+ $txlocaltax2 = 0;
+ }
+ if (empty($remise)) {
+ $remise = 0;
+ }
+ if (empty($remise_percent)) {
+ $remise_percent = 0;
+ }
$remise_percent = price2num($remise_percent);
$qty = price2num($qty);
- if (!$qty) $qty = 1;
+ if (!$qty) {
+ $qty = 1;
+ }
$pu = price2num($pu);
$pu_ht_devise = price2num($pu_ht_devise);
- if (!preg_match('/\((.*)\)/', $txtva)) {
- $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
- }
+ if (!preg_match('/\((.*)\)/', $txtva)) {
+ $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
+ }
$txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2);
// Check parameters
- if ($type < 0) return -1;
+ if ($type < 0) {
+ return -1;
+ }
if ($date_start && $date_end && $date_start > $date_end) {
$langs->load("errors");
$this->error = $langs->trans('ErrorStartDateGreaterEnd');
@@ -2582,8 +2563,7 @@ class CommandeFournisseur extends CommonOrder
// Clean vat code
$reg = array();
$vat_src_code = '';
- if (preg_match('/\((.*)\)/', $txtva, $reg))
- {
+ if (preg_match('/\((.*)\)/', $txtva, $reg)) {
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
@@ -2621,14 +2601,11 @@ class CommandeFournisseur extends CommonOrder
$this->line->desc = $desc;
// redefine quantity according to packaging
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
- {
- if ($qty < $this->line->packaging)
- {
+ if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
+ if ($qty < $this->line->packaging) {
$qty = $this->line->packaging;
} else {
- if (($qty % $this->line->packaging) > 0)
- {
+ if (($qty % $this->line->packaging) > 0) {
$coeff = intval($qty / $this->line->packaging) + 1;
$qty = $this->line->packaging * $coeff;
setEventMessage($langs->trans('QtyRecalculatedWithPackaging'), 'mesgs');
@@ -2686,8 +2663,7 @@ class CommandeFournisseur extends CommonOrder
// Mise a jour info denormalisees au niveau facture
- if ($result >= 0)
- {
+ if ($result >= 0) {
$this->update_price('', 'auto');
$this->db->commit();
return $result;
@@ -2730,8 +2706,7 @@ class CommandeFournisseur extends CommonOrder
$sql .= $this->db->order("rowid", "ASC");
$sql .= $this->db->plimit(1);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$obj = $this->db->fetch_object($resql);
$prodid = $obj->rowid;
}
@@ -2758,8 +2733,7 @@ class CommandeFournisseur extends CommonOrder
// Lines
$nbp = 5;
$xnbp = 0;
- while ($xnbp < $nbp)
- {
+ while ($xnbp < $nbp) {
$line = new CommandeFournisseurLigne($this->db);
$line->desc = $langs->trans("Description")." ".$xnbp;
$line->qty = 1;
@@ -2768,8 +2742,7 @@ class CommandeFournisseur extends CommonOrder
$line->tva_tx = 19.6;
$line->localtax1_tx = 0;
$line->localtax2_tx = 0;
- if ($xnbp == 2)
- {
+ if ($xnbp == 2) {
$line->total_ht = 50;
$line->total_ttc = 59.8;
$line->total_tva = 9.8;
@@ -2806,17 +2779,25 @@ class CommandeFournisseur extends CommonOrder
$sql .= ' WHERE c.rowid = '.$id;
$result = $this->db->query($sql);
- if ($result)
- {
- if ($this->db->num_rows($result))
- {
+ if ($result) {
+ if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
- if ($obj->fk_user_author) $this->user_creation_id = $obj->fk_user_author;
- if ($obj->fk_user_valid) $this->user_validation_id = $obj->fk_user_valid;
- if ($obj->fk_user_modif) $this->user_modification_id = $obj->fk_user_modif;
- if ($obj->fk_user_approve) $this->user_approve_id = $obj->fk_user_approve;
- if ($obj->fk_user_approve2) $this->user_approve_id2 = $obj->fk_user_approve2;
+ if ($obj->fk_user_author) {
+ $this->user_creation_id = $obj->fk_user_author;
+ }
+ if ($obj->fk_user_valid) {
+ $this->user_validation_id = $obj->fk_user_valid;
+ }
+ if ($obj->fk_user_modif) {
+ $this->user_modification_id = $obj->fk_user_modif;
+ }
+ if ($obj->fk_user_approve) {
+ $this->user_approve_id = $obj->fk_user_approve;
+ }
+ if ($obj->fk_user_approve2) {
+ $this->user_approve_id2 = $obj->fk_user_approve2;
+ }
$this->date_creation = $this->db->idate($obj->datec);
$this->date_modification = $this->db->idate($obj->datem);
@@ -2847,8 +2828,7 @@ class CommandeFournisseur extends CommonOrder
$sql = "SELECT count(co.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as co";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON co.fk_soc = s.rowid";
- 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";
@@ -2856,10 +2836,8 @@ class CommandeFournisseur extends CommonOrder
$sql .= " ".$clause." co.entity = ".$conf->entity;
$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["supplier_orders"] = $obj->nb;
}
$this->db->free($resql);
@@ -2888,8 +2866,7 @@ class CommandeFournisseur extends CommonOrder
$sql = "SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date";
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
- 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 c.fk_soc = sc.fk_soc";
$sql .= " WHERE sc.fk_user = ".$user->id;
$clause = " AND";
@@ -2900,11 +2877,12 @@ class CommandeFournisseur extends CommonOrder
} else {
$sql .= " AND c.fk_statut IN (".self::STATUS_VALIDATED.", ".self::STATUS_ACCEPTED.")";
}
- if ($user->socid) $sql .= " AND c.fk_soc = ".$user->socid;
+ if ($user->socid) {
+ $sql .= " AND c.fk_soc = ".$user->socid;
+ }
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$commandestatic = new CommandeFournisseur($this->db);
$response = new WorkboardResponse();
@@ -2920,8 +2898,7 @@ class CommandeFournisseur extends CommonOrder
$response->url = DOL_URL_ROOT.'/fourn/commande/list.php?statut=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
}
- while ($obj = $this->db->fetch_object($resql))
- {
+ while ($obj = $this->db->fetch_object($resql)) {
$response->nbtodo++;
$commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
@@ -2950,27 +2927,25 @@ class CommandeFournisseur extends CommonOrder
{
global $db, $langs;
- if ($this->methode_commande_id > 0)
- {
+ if ($this->methode_commande_id > 0) {
$sql = "SELECT rowid, code, libelle as label";
$sql .= " FROM ".MAIN_DB_PREFIX.'c_input_method';
$sql .= " WHERE active=1 AND rowid = ".$this->db->escape($this->methode_commande_id);
$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);
$string = $langs->trans($obj->code);
- if ($string == $obj->code)
- {
+ if ($string == $obj->code) {
$string = $obj->label != '-' ? $obj->label : '';
}
return $string;
}
- } else dol_print_error($this->db);
+ } else {
+ dol_print_error($this->db);
+ }
}
return '';
@@ -3017,26 +2992,30 @@ class CommandeFournisseur extends CommonOrder
*/
public function getMaxDeliveryTimeDay($langs)
{
- if (empty($this->lines)) return '';
+ if (empty($this->lines)) {
+ return '';
+ }
$obj = new ProductFournisseur($this->db);
$nb = 0;
- foreach ($this->lines as $line)
- {
- if ($line->fk_product > 0)
- {
+ foreach ($this->lines as $line) {
+ if ($line->fk_product > 0) {
$idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
- if ($idp)
- {
+ if ($idp) {
$obj->fetch($idp);
- if ($obj->delivery_time_days > $nb) $nb = $obj->delivery_time_days;
+ if ($obj->delivery_time_days > $nb) {
+ $nb = $obj->delivery_time_days;
+ }
}
}
}
- if ($nb === 0) return '';
- else return $nb.' '.$langs->trans('Days');
+ if ($nb === 0) {
+ return '';
+ } else {
+ return $nb.' '.$langs->trans('Days');
+ }
}
/**
@@ -3079,7 +3058,9 @@ class CommandeFournisseur extends CommonOrder
{
global $conf;
- if (empty($this->delivery_date) && !empty($this->date_livraison)) $this->delivery_date = $this->date_livraison; // For backward compatibility
+ if (empty($this->delivery_date) && !empty($this->date_livraison)) {
+ $this->delivery_date = $this->date_livraison; // For backward compatibility
+ }
if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) {
$now = dol_now();
@@ -3110,7 +3091,9 @@ class CommandeFournisseur extends CommonOrder
{
global $conf, $langs;
- if (empty($this->delivery_date) && !empty($this->date_livraison)) $this->delivery_date = $this->date_livraison; // For backward compatibility
+ if (empty($this->delivery_date) && !empty($this->date_livraison)) {
+ $this->delivery_date = $this->date_livraison; // For backward compatibility
+ }
$text = '';
@@ -3143,8 +3126,7 @@ class CommandeFournisseur extends CommonOrder
{
global $conf, $langs;
- 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)) {
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
$qtydelivered = array();
@@ -3171,7 +3153,9 @@ class CommandeFournisseur extends CommonOrder
}
foreach ($this->lines as $line) {
// Exclude lines not qualified for shipment, similar code is found into interface_20_modWrokflow for customers
- if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $line->product_type > 0) continue;
+ if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $line->product_type > 0) {
+ continue;
+ }
$qtywished[$line->fk_product] += $line->qty;
}
@@ -3181,16 +3165,14 @@ class CommandeFournisseur extends CommonOrder
$keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished)); // To check we also have same number of keys
/*var_dump(array_keys($qtydelivered));
- var_dump(array_keys($qtywished));
- var_dump($diff_array);
- var_dump($keysinwishednotindelivered);
- var_dump($keysindeliverednotinwished);
- exit;*/
+ var_dump(array_keys($qtywished));
+ var_dump($diff_array);
+ var_dump($keysinwishednotindelivered);
+ var_dump($keysindeliverednotinwished);
+ exit;*/
- if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) //No diff => mean everythings is received
- {
- if ($closeopenorder)
- {
+ if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) { //No diff => mean everythings is received
+ if ($closeopenorder) {
//$ret=$this->setStatus($user,5);
$ret = $this->Livraison($user, $date_liv, 'tot', $comment); // GETPOST("type") is 'tot', 'par', 'nev', 'can'
if ($ret < 0) {
@@ -3211,16 +3193,13 @@ class CommandeFournisseur extends CommonOrder
$close = 0;
- if (count($diff_array) > 0)
- {
+ if (count($diff_array) > 0) {
//there are some difference between the two arrays
//scan the array of results
- foreach ($diff_array as $key => $value)
- {
+ foreach ($diff_array as $key => $value) {
//if the quantity delivered is greater or equal to wish quantity
- if ($qtydelivered[$key] >= $qtywished[$key])
- {
+ if ($qtydelivered[$key] >= $qtywished[$key]) {
$close++;
}
}
@@ -3280,25 +3259,31 @@ class CommandeFournisseur extends CommonOrder
$sql = 'SELECT cd.rowid, cd.fk_product,';
$sql .= ' sum(cfd.qty) as qty';
$sql .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch as cfd,';
- if ($filtre_statut >= 0) $sql .= ' '.MAIN_DB_PREFIX.'reception as e,';
+ if ($filtre_statut >= 0) {
+ $sql .= ' '.MAIN_DB_PREFIX.'reception as e,';
+ }
$sql .= ' '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd';
$sql .= ' WHERE';
- if ($filtre_statut >= 0) $sql .= ' cfd.fk_reception = e.rowid AND';
+ if ($filtre_statut >= 0) {
+ $sql .= ' cfd.fk_reception = e.rowid AND';
+ }
$sql .= ' cfd.fk_commandefourndet = cd.rowid';
$sql .= ' AND cd.fk_commande ='.$this->id;
- if ($this->fk_product > 0) $sql .= ' AND cd.fk_product = '.$this->fk_product;
- if ($filtre_statut >= 0) $sql .= ' AND e.fk_statut >= '.$filtre_statut;
+ if ($this->fk_product > 0) {
+ $sql .= ' AND cd.fk_product = '.$this->fk_product;
+ }
+ if ($filtre_statut >= 0) {
+ $sql .= ' AND e.fk_statut >= '.$filtre_statut;
+ }
$sql .= ' GROUP BY cd.rowid, cd.fk_product';
dol_syslog(get_class($this)."::loadReceptions", LOG_DEBUG);
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$num = $this->db->num_rows($result);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $this->db->fetch_object($result);
empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
$i++;
@@ -3399,20 +3384,20 @@ class CommandeFournisseurLigne extends CommonOrderLine
$sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
$sql .= ' cd.date_start, cd.date_end, cd.fk_unit,';
$sql .= ' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc';
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
+ if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$sql .= ", pfp.rowid as fk_pfp, pfp.packaging";
+ }
$sql .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid';
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
+ if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON cd.fk_product = pfp.fk_product and cd.ref = pfp.ref_fourn";
+ }
$sql .= ' WHERE cd.rowid = '.$rowid;
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$objp = $this->db->fetch_object($result);
- if (!empty($objp))
- {
+ if (!empty($objp)) {
$this->rowid = $objp->rowid;
$this->id = $objp->rowid;
$this->fk_commande = $objp->fk_commande;
@@ -3443,8 +3428,7 @@ class CommandeFournisseurLigne extends CommonOrderLine
$this->product_ref = $objp->product_ref;
$this->product_label = $objp->product_label;
$this->product_desc = $objp->product_desc;
- if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
- {
+ if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
$this->packaging = $objp->packaging;
$this->fk_fournprice = $objp->fk_pfp;
}
@@ -3488,32 +3472,63 @@ class CommandeFournisseurLigne extends CommonOrderLine
dol_syslog(get_class($this)."::insert rang=".$this->rang);
// Clean parameters
- if (empty($this->tva_tx)) $this->tva_tx = 0;
- if (empty($this->localtax1_tx)) $this->localtax1_tx = 0;
- if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
- if (empty($this->localtax1_type)) $this->localtax1_type = '0';
- if (empty($this->localtax2_type)) $this->localtax2_type = '0';
- if (empty($this->total_localtax1)) $this->total_localtax1 = 0;
- if (empty($this->total_localtax2)) $this->total_localtax2 = 0;
- if (empty($this->rang)) $this->rang = 0;
- if (empty($this->remise)) $this->remise = 0;
- if (empty($this->remise_percent)) $this->remise_percent = 0;
- if (empty($this->info_bits)) $this->info_bits = 0;
- if (empty($this->special_code)) $this->special_code = 0;
- if (empty($this->fk_parent_line)) $this->fk_parent_line = 0;
- if (empty($this->pa_ht)) $this->pa_ht = 0;
+ if (empty($this->tva_tx)) {
+ $this->tva_tx = 0;
+ }
+ if (empty($this->localtax1_tx)) {
+ $this->localtax1_tx = 0;
+ }
+ if (empty($this->localtax2_tx)) {
+ $this->localtax2_tx = 0;
+ }
+ if (empty($this->localtax1_type)) {
+ $this->localtax1_type = '0';
+ }
+ if (empty($this->localtax2_type)) {
+ $this->localtax2_type = '0';
+ }
+ if (empty($this->total_localtax1)) {
+ $this->total_localtax1 = 0;
+ }
+ if (empty($this->total_localtax2)) {
+ $this->total_localtax2 = 0;
+ }
+ if (empty($this->rang)) {
+ $this->rang = 0;
+ }
+ if (empty($this->remise)) {
+ $this->remise = 0;
+ }
+ if (empty($this->remise_percent)) {
+ $this->remise_percent = 0;
+ }
+ if (empty($this->info_bits)) {
+ $this->info_bits = 0;
+ }
+ if (empty($this->special_code)) {
+ $this->special_code = 0;
+ }
+ if (empty($this->fk_parent_line)) {
+ $this->fk_parent_line = 0;
+ }
+ if (empty($this->pa_ht)) {
+ $this->pa_ht = 0;
+ }
// Multicurrency
- if (!empty($this->multicurrency_code)) list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code);
- if (empty($this->fk_multicurrency))
- {
+ if (!empty($this->multicurrency_code)) {
+ list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code);
+ }
+ if (empty($this->fk_multicurrency)) {
$this->multicurrency_code = $conf->currency;
$this->fk_multicurrency = 0;
$this->multicurrency_tx = 1;
}
// Check parameters
- if ($this->product_type < 0) return -1;
+ if ($this->product_type < 0) {
+ return -1;
+ }
$this->db->begin();
@@ -3528,7 +3543,11 @@ class CommandeFournisseurLigne extends CommonOrderLine
$sql .= " VALUES (".$this->fk_commande.", '".$this->db->escape($this->label)."','".$this->db->escape($this->desc)."',";
$sql .= " ".($this->date_start ? "'".$this->db->idate($this->date_start)."'" : "null").",";
$sql .= " ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null").",";
- if ($this->fk_product) { $sql .= $this->fk_product.","; } else { $sql .= "null,"; }
+ if ($this->fk_product) {
+ $sql .= $this->fk_product.",";
+ } else {
+ $sql .= "null,";
+ }
$sql .= "'".$this->db->escape($this->product_type)."',";
$sql .= "'".$this->db->escape($this->special_code)."',";
$sql .= "'".$this->db->escape($this->rang)."',";
@@ -3556,25 +3575,23 @@ class CommandeFournisseurLigne extends CommonOrderLine
dol_syslog(get_class($this)."::insert", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
$this->rowid = $this->id;
- if (!$error)
- {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('LINEORDER_SUPPLIER_CREATE', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
@@ -3583,8 +3600,7 @@ class CommandeFournisseurLigne extends CommonOrderLine
return 1;
}
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->errors[] = ($this->errors ? ', '.$errmsg : $errmsg);
}
@@ -3647,32 +3663,26 @@ class CommandeFournisseurLigne extends CommonOrderLine
dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
$result = $this->db->query($sql);
- if ($result > 0)
- {
- if (!$error)
- {
+ if ($result > 0) {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
global $user;
// Call trigger
$result = $this->call_trigger('LINEORDER_SUPPLIER_UPDATE', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->db->rollback();
return -1;
}
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
@@ -3702,8 +3712,7 @@ class CommandeFournisseurLigne extends CommonOrderLine
// extrafields
$result = $this->deleteExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$this->db->rollback();
return -1;
}
@@ -3712,24 +3721,22 @@ class CommandeFournisseurLigne extends CommonOrderLine
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
- if (!$notrigger)
- {
+ if ($resql) {
+ if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('LINEORDER_SUPPLIER_DELETE', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
}
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
diff --git a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php
index a7abed27369..c79a53297f2 100644
--- a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php
@@ -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 ''.$langs->trans($this->statutshort[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut0');
- elseif ($status == 1) return ''.$langs->trans($this->statutshort[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut4');
- elseif ($status == 2) return ''.$langs->trans($this->statutshort[$status]).' '.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 ''.$langs->trans($this->statutshort[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut0');
+ } elseif ($status == 1) {
+ return ''.$langs->trans($this->statutshort[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut4');
+ } elseif ($status == 2) {
+ return ''.$langs->trans($this->statutshort[$status]).' '.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,";
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index 0157dbd0eec..2336b22a366 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -38,8 +38,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commoninvoice.class.php';
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
-if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
-if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
+if (!empty($conf->accounting->enabled)) {
+ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
+}
+if (!empty($conf->accounting->enabled)) {
+ require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
+}
/**
* Class to manage suppliers invoices
@@ -350,9 +354,15 @@ class FactureFournisseur extends CommonInvoice
$now = dol_now();
// Clean parameters
- if (isset($this->ref_supplier)) $this->ref_supplier = trim($this->ref_supplier);
- if (empty($this->type)) $this->type = self::TYPE_STANDARD;
- if (empty($this->date)) $this->date = $now;
+ if (isset($this->ref_supplier)) {
+ $this->ref_supplier = trim($this->ref_supplier);
+ }
+ if (empty($this->type)) {
+ $this->type = self::TYPE_STANDARD;
+ }
+ if (empty($this->date)) {
+ $this->date = $now;
+ }
$socid = $this->socid;
$ref_supplier = $this->ref_supplier;
@@ -360,10 +370,12 @@ class FactureFournisseur extends CommonInvoice
$remise = $this->remise;
// Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if not using origin rate)
- if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date);
- else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
- if (empty($this->fk_multicurrency))
- {
+ if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
+ list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date);
+ } else {
+ $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
+ }
+ if (empty($this->fk_multicurrency)) {
$this->multicurrency_code = $conf->currency;
$this->fk_multicurrency = 0;
$this->multicurrency_tx = 1;
@@ -371,7 +383,9 @@ class FactureFournisseur extends CommonInvoice
$this->db->begin();
- if (!$remise) $remise = 0;
+ if (!$remise) {
+ $remise = 0;
+ }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn (";
$sql .= "ref";
@@ -423,8 +437,7 @@ class FactureFournisseur extends CommonInvoice
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn');
// Update ref with new one
@@ -433,25 +446,21 @@ class FactureFournisseur extends CommonInvoice
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql) $error++;
+ if (!$resql) {
+ $error++;
+ }
- if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects
- {
+ if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
$this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
}
// Add object linked
- if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects))
- {
- foreach ($this->linked_objects as $origin => $tmp_origin_id)
- {
- if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
- {
- foreach ($tmp_origin_id as $origin_id)
- {
+ if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
+ foreach ($this->linked_objects as $origin => $tmp_origin_id) {
+ if (is_array($tmp_origin_id)) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
+ foreach ($tmp_origin_id as $origin_id) {
$ret = $this->add_object_linked($origin, $origin_id);
- if (!$ret)
- {
+ if (!$ret) {
dol_print_error($this->db);
$error++;
}
@@ -460,8 +469,7 @@ class FactureFournisseur extends CommonInvoice
{
$origin_id = $tmp_origin_id;
$ret = $this->add_object_linked($origin, $origin_id);
- if (!$ret)
- {
+ if (!$ret) {
dol_print_error($this->db);
$error++;
}
@@ -469,17 +477,14 @@ class FactureFournisseur extends CommonInvoice
}
}
- if (count($this->lines) && is_object($this->lines[0])) // If this->lines is array of InvoiceLines (preferred mode)
- {
+ if (count($this->lines) && is_object($this->lines[0])) { // If this->lines is array of InvoiceLines (preferred mode)
dol_syslog("There is ".count($this->lines)." lines that are invoice lines objects");
- foreach ($this->lines as $i => $val)
- {
+ foreach ($this->lines as $i => $val) {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn, special_code)';
$sql .= ' VALUES ('.$this->id.','.intval($this->lines[$i]->special_code).')';
$resql_insert = $this->db->query($sql);
- if ($resql_insert)
- {
+ if ($resql_insert) {
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
$this->updateline(
@@ -511,20 +516,20 @@ class FactureFournisseur extends CommonInvoice
} else // If this->lines is an array of invoice line arrays
{
dol_syslog("There is ".count($this->lines)." lines that are array lines");
- foreach ($this->lines as $i => $val)
- {
+ foreach ($this->lines as $i => $val) {
$line = $this->lines[$i];
// Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
//if (! is_object($line)) $line=json_decode(json_encode($line), false); // convert recursively array into object.
- if (!is_object($line)) $line = (object) $line;
+ if (!is_object($line)) {
+ $line = (object) $line;
+ }
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn, special_code)';
$sql .= ' VALUES ('.$this->id.','.intval($this->lines[$i]->special_code).')';
$resql_insert = $this->db->query($sql);
- if ($resql_insert)
- {
+ if ($resql_insert) {
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
$this->updateline(
@@ -539,7 +544,7 @@ class FactureFournisseur extends CommonInvoice
'HT',
(!empty($line->info_bits) ? $line->info_bits : ''),
$line->product_type
- );
+ );
} else {
$this->error = $this->db->lasterror();
$this->db->rollback();
@@ -550,28 +555,25 @@ class FactureFournisseur extends CommonInvoice
// Update total price
$result = $this->update_price();
- if ($result > 0)
- {
+ if ($result > 0) {
// Actions on extra fields
- if (!$error)
- {
+ if (!$error) {
$result = $this->insertExtraFields(); // This also set $this->error or $this->errors if errors are found
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error)
- {
+ if (!$error) {
// Call trigger
$result = $this->call_trigger('BILL_SUPPLIER_CREATE', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return $this->id;
} else {
@@ -584,8 +586,7 @@ class FactureFournisseur extends CommonInvoice
return -3;
}
} else {
- if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
- {
+ if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
$this->error = $langs->trans('ErrorRefAlreadyExists');
$this->db->rollback();
return -1;
@@ -655,15 +656,17 @@ class FactureFournisseur extends CommonInvoice
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON t.fk_cond_reglement = cr.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON t.fk_mode_reglement = p.id";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON t.fk_incoterms = i.rowid';
- if ($id) $sql .= " WHERE t.rowid=".$id;
- if ($ref) $sql .= " WHERE t.ref='".$this->db->escape($ref)."' AND t.entity IN (".getEntity('supplier_invoice').")";
+ if ($id) {
+ $sql .= " WHERE t.rowid=".$id;
+ }
+ if ($ref) {
+ $sql .= " WHERE t.ref='".$this->db->escape($ref)."' AND t.entity IN (".getEntity('supplier_invoice').")";
+ }
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$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;
@@ -737,11 +740,12 @@ class FactureFournisseur extends CommonInvoice
// fetch optionals attributes and labels
$this->fetch_optionals();
- if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1;
+ if ($this->statut == self::STATUS_DRAFT) {
+ $this->brouillon = 1;
+ }
$result = $this->fetch_lines();
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $this->db->lasterror();
return -3;
}
@@ -783,14 +787,11 @@ class FactureFournisseur extends CommonInvoice
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
$resql_rows = $this->db->query($sql);
- if ($resql_rows)
- {
+ if ($resql_rows) {
$num_rows = $this->db->num_rows($resql_rows);
- if ($num_rows)
- {
+ if ($num_rows) {
$i = 0;
- while ($i < $num_rows)
- {
+ while ($i < $num_rows) {
$obj = $this->db->fetch_object($resql_rows);
$line = new SupplierInvoiceLine($this->db);
@@ -877,37 +878,95 @@ class FactureFournisseur extends CommonInvoice
$error = 0;
// Clean parameters
- if (empty($this->type)) $this->type = self::TYPE_STANDARD;
- if (isset($this->ref)) $this->ref = trim($this->ref);
- if (isset($this->ref_supplier)) $this->ref_supplier = trim($this->ref_supplier);
- if (isset($this->entity)) $this->entity = trim($this->entity);
- if (isset($this->type)) $this->type = trim($this->type);
- if (isset($this->fk_soc)) $this->fk_soc = trim($this->fk_soc);
- if (isset($this->label)) $this->label = trim($this->label);
- if (isset($this->libelle)) $this->libelle = trim($this->libelle); // deprecated
- if (isset($this->paye)) $this->paye = trim($this->paye);
- if (isset($this->amount)) $this->amount = trim($this->amount);
- if (isset($this->remise)) $this->remise = trim($this->remise);
- if (isset($this->close_code)) $this->close_code = trim($this->close_code);
- if (isset($this->close_note)) $this->close_note = trim($this->close_note);
- if (isset($this->tva)) $this->tva = trim($this->tva);
- if (isset($this->localtax1)) $this->localtax1 = trim($this->localtax1);
- if (isset($this->localtax2)) $this->localtax2 = trim($this->localtax2);
- if (empty($this->total_ht)) $this->total_ht = 0;
- if (empty($this->total_tva)) $this->total_tva = 0;
+ if (empty($this->type)) {
+ $this->type = self::TYPE_STANDARD;
+ }
+ if (isset($this->ref)) {
+ $this->ref = trim($this->ref);
+ }
+ if (isset($this->ref_supplier)) {
+ $this->ref_supplier = trim($this->ref_supplier);
+ }
+ if (isset($this->entity)) {
+ $this->entity = trim($this->entity);
+ }
+ if (isset($this->type)) {
+ $this->type = trim($this->type);
+ }
+ if (isset($this->fk_soc)) {
+ $this->fk_soc = trim($this->fk_soc);
+ }
+ if (isset($this->label)) {
+ $this->label = trim($this->label);
+ }
+ if (isset($this->libelle)) {
+ $this->libelle = trim($this->libelle); // deprecated
+ }
+ if (isset($this->paye)) {
+ $this->paye = trim($this->paye);
+ }
+ if (isset($this->amount)) {
+ $this->amount = trim($this->amount);
+ }
+ if (isset($this->remise)) {
+ $this->remise = trim($this->remise);
+ }
+ if (isset($this->close_code)) {
+ $this->close_code = trim($this->close_code);
+ }
+ if (isset($this->close_note)) {
+ $this->close_note = trim($this->close_note);
+ }
+ if (isset($this->tva)) {
+ $this->tva = trim($this->tva);
+ }
+ if (isset($this->localtax1)) {
+ $this->localtax1 = trim($this->localtax1);
+ }
+ if (isset($this->localtax2)) {
+ $this->localtax2 = trim($this->localtax2);
+ }
+ if (empty($this->total_ht)) {
+ $this->total_ht = 0;
+ }
+ if (empty($this->total_tva)) {
+ $this->total_tva = 0;
+ }
// if (isset($this->total_localtax1)) $this->total_localtax1=trim($this->total_localtax1);
// if (isset($this->total_localtax2)) $this->total_localtax2=trim($this->total_localtax2);
- if (isset($this->total_ttc)) $this->total_ttc = trim($this->total_ttc);
- if (isset($this->statut)) $this->statut = (int) $this->statut;
- if (isset($this->author)) $this->author = trim($this->author);
- if (isset($this->fk_user_valid)) $this->fk_user_valid = trim($this->fk_user_valid);
- if (isset($this->fk_facture_source)) $this->fk_facture_source = trim($this->fk_facture_source);
- if (isset($this->fk_project)) $this->fk_project = trim($this->fk_project);
- if (isset($this->cond_reglement_id)) $this->cond_reglement_id = trim($this->cond_reglement_id);
- if (isset($this->note_private)) $this->note = trim($this->note_private);
- if (isset($this->note_public)) $this->note_public = trim($this->note_public);
- if (isset($this->model_pdf)) $this->model_pdf = trim($this->model_pdf);
- if (isset($this->import_key)) $this->import_key = trim($this->import_key);
+ if (isset($this->total_ttc)) {
+ $this->total_ttc = trim($this->total_ttc);
+ }
+ if (isset($this->statut)) {
+ $this->statut = (int) $this->statut;
+ }
+ if (isset($this->author)) {
+ $this->author = trim($this->author);
+ }
+ if (isset($this->fk_user_valid)) {
+ $this->fk_user_valid = trim($this->fk_user_valid);
+ }
+ if (isset($this->fk_facture_source)) {
+ $this->fk_facture_source = trim($this->fk_facture_source);
+ }
+ if (isset($this->fk_project)) {
+ $this->fk_project = trim($this->fk_project);
+ }
+ if (isset($this->cond_reglement_id)) {
+ $this->cond_reglement_id = trim($this->cond_reglement_id);
+ }
+ if (isset($this->note_private)) {
+ $this->note = trim($this->note_private);
+ }
+ if (isset($this->note_public)) {
+ $this->note_public = trim($this->note_public);
+ }
+ if (isset($this->model_pdf)) {
+ $this->model_pdf = trim($this->model_pdf);
+ }
+ if (isset($this->import_key)) {
+ $this->import_key = trim($this->import_key);
+ }
// Check parameters
@@ -922,7 +981,9 @@ class FactureFournisseur extends CommonInvoice
$sql .= " fk_soc=".(isset($this->fk_soc) ? $this->fk_soc : "null").",";
$sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
$sql .= " datef=".(dol_strlen($this->date) != 0 ? "'".$this->db->idate($this->date)."'" : 'null').",";
- if (dol_strlen($this->tms) != 0) $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
+ if (dol_strlen($this->tms) != 0) {
+ $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
+ }
$sql .= " libelle=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
$sql .= " paye=".(isset($this->paye) ? $this->paye : "null").",";
$sql .= " amount=".(isset($this->amount) ? $this->amount : "null").",";
@@ -963,31 +1024,27 @@ class FactureFournisseur extends CommonInvoice
}
}
- if (!$error)
- {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error)
- {
- if (!$notrigger)
- {
+ if (!$error) {
+ if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('BILL_SUPPLIER_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(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -1019,10 +1076,8 @@ class FactureFournisseur extends CommonInvoice
$remise = new DiscountAbsolute($this->db);
$result = $remise->fetch($idremise);
- if ($result > 0)
- {
- if ($remise->fk_invoice_supplier) // Protection against multiple submission
- {
+ if ($result > 0) {
+ if ($remise->fk_invoice_supplier) { // Protection against multiple submission
$this->error = $langs->trans("ErrorDiscountAlreadyUsed");
$this->db->rollback();
return -5;
@@ -1043,8 +1098,7 @@ class FactureFournisseur extends CommonInvoice
$facligne->info_bits = 2;
// Get buy/cost price of invoice that is source of discount
- if ($remise->fk_invoice_supplier_source > 0)
- {
+ if ($remise->fk_invoice_supplier_source > 0) {
$srcinvoice = new FactureFournisseur($this->db);
$srcinvoice->fetch($remise->fk_invoice_supplier_source);
$totalcostpriceofinvoice = 0;
@@ -1064,15 +1118,12 @@ class FactureFournisseur extends CommonInvoice
$facligne->multicurrency_total_ttc = -$remise->multicurrency_total_ttc;
$lineid = $facligne->insert();
- if ($lineid > 0)
- {
+ if ($lineid > 0) {
$result = $this->update_price(1);
- if ($result > 0)
- {
+ if ($result > 0) {
// Create link between discount and invoice line
$result = $remise->link_to_invoice($lineid, 0, 'supplier');
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $remise->error;
$this->db->rollback();
return -4;
@@ -1117,12 +1168,10 @@ class FactureFournisseur extends CommonInvoice
$error = 0;
$this->db->begin();
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('BILL_SUPPLIER_DELETE', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->db->rollback();
return -1;
}
@@ -1156,8 +1205,7 @@ class FactureFournisseur extends CommonInvoice
}
}
- if (!$error)
- {
+ if (!$error) {
$main = MAIN_DB_PREFIX.'facture_fourn_det';
$ef = $main."_extrafields";
$sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_facture_fourn = $rowid)";
@@ -1165,8 +1213,7 @@ class FactureFournisseur extends CommonInvoice
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det WHERE fk_facture_fourn = '.$rowid.';';
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resqlef && $resql)
- {
+ if ($resqlef && $resql) {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn WHERE rowid = '.$rowid;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql2 = $this->db->query($sql);
@@ -1178,47 +1225,43 @@ class FactureFournisseur extends CommonInvoice
}
}
- if (!$error)
- {
+ if (!$error) {
// Delete linked object
$res = $this->deleteObjectLinked();
- if ($res < 0) $error++;
+ if ($res < 0) {
+ $error++;
+ }
}
- if (!$error)
- {
+ if (!$error) {
// Delete linked object
$res = $this->deleteObjectLinked();
- if ($res < 0) $error++;
+ if ($res < 0) {
+ $error++;
+ }
}
- if (!$error)
- {
+ if (!$error) {
// Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive
$this->deleteEcmFiles();
// We remove directory
- if ($conf->fournisseur->facture->dir_output)
- {
+ if ($conf->fournisseur->facture->dir_output) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$ref = dol_sanitizeFileName($this->ref);
$dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoive_supplier').$ref;
$file = $dir."/".$ref.".pdf";
- if (file_exists($file))
- {
- if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers
- {
+ if (file_exists($file)) {
+ if (!dol_delete_file($file, 0, 0, 0, $this)) { // For triggers
$this->error = 'ErrorFailToDeleteFile';
$error++;
}
}
- if (file_exists($dir))
- {
+ if (file_exists($dir)) {
$res = @dol_delete_dir_recursive($dir);
- if (!$res)
- {
+ if (!$res) {
$this->error = 'ErrorFailToDeleteDir';
$error++;
}
@@ -1227,18 +1270,15 @@ class FactureFournisseur extends CommonInvoice
}
// Remove extrafields
- if (!$error)
- {
+ if (!$error) {
$result = $this->deleteExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
}
- if (!$error)
- {
+ if (!$error) {
dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG);
$this->db->commit();
return 1;
@@ -1289,11 +1329,12 @@ class FactureFournisseur extends CommonInvoice
dol_syslog("FactureFournisseur::set_paid", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
// Call trigger
$result = $this->call_trigger('BILL_SUPPLIER_PAYED', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
} else {
$error++;
@@ -1301,8 +1342,7 @@ class FactureFournisseur extends CommonInvoice
dol_print_error($this->db);
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
@@ -1350,11 +1390,12 @@ class FactureFournisseur extends CommonInvoice
dol_syslog("FactureFournisseur::set_unpaid", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
// Call trigger
$result = $this->call_trigger('BILL_SUPPLIER_UNPAYED', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
} else {
$error++;
@@ -1362,8 +1403,7 @@ class FactureFournisseur extends CommonInvoice
dol_syslog("FactureFournisseur::set_unpaid ".$this->error);
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
@@ -1397,19 +1437,16 @@ class FactureFournisseur extends CommonInvoice
$this->fetch_lines();
// Check parameters
- if ($this->statut > self::STATUS_DRAFT) // This is to avoid to validate twice (avoid errors on logs and stock management)
- {
+ if ($this->statut > self::STATUS_DRAFT) { // This is to avoid to validate twice (avoid errors on logs and stock management)
dol_syslog(get_class($this)."::validate no draft status", LOG_WARNING);
return 0;
}
- if (preg_match('/^'.preg_quote($langs->trans("CopyOf").' ').'/', $this->ref_supplier))
- {
+ if (preg_match('/^'.preg_quote($langs->trans("CopyOf").' ').'/', $this->ref_supplier)) {
$langs->load("errors");
$this->error = $langs->trans("ErrorFieldFormat", $langs->transnoentities("RefSupplier")).'. '.$langs->trans('RemoveString', $langs->transnoentitiesnoconv("CopyOf"));
return -1;
}
- if (count($this->lines) <= 0)
- {
+ if (count($this->lines) <= 0) {
$langs->load("errors");
$this->error = $langs->trans("ErrorObjectMustHaveLinesToBeValidated", $this->ref);
return -1;
@@ -1418,11 +1455,9 @@ class FactureFournisseur extends CommonInvoice
$this->db->begin();
// Define new ref
- if ($force_number)
- {
+ if ($force_number) {
$num = $force_number;
- } elseif (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life
- {
+ } elseif (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
$num = $this->getNextNumRef($this->thirdparty);
} else {
$num = $this->ref;
@@ -1435,71 +1470,72 @@ class FactureFournisseur extends CommonInvoice
dol_syslog(get_class($this)."::validate", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
// Si on incrémente le produit principal et ses composants à la validation de facture fournisseur
- if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL))
- {
+ if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) {
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
$langs->load("agenda");
$cpt = count($this->lines);
- for ($i = 0; $i < $cpt; $i++)
- {
- if ($this->lines[$i]->fk_product > 0)
- {
+ for ($i = 0; $i < $cpt; $i++) {
+ if ($this->lines[$i]->fk_product > 0) {
$this->line = $this->lines[$i];
$mouvP = new MouvementStock($this->db);
$mouvP->origin = &$this;
// We increase stock for product
$up_ht_disc = $this->lines[$i]->pu_ht;
- if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc = price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU');
- if ($this->type == FactureFournisseur::TYPE_CREDIT_NOTE) $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr", $num));
- else $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr", $num));
- if ($result < 0) { $error++; }
+ if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) {
+ $up_ht_disc = price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU');
+ }
+ if ($this->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
+ $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr", $num));
+ } else {
+ $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr", $num));
+ }
+ if ($result < 0) {
+ $error++;
+ }
unset($this->line);
}
}
}
// Triggers call
- if (!$error && empty($notrigger))
- {
+ if (!$error && empty($notrigger)) {
// Call trigger
$result = $this->call_trigger('BILL_SUPPLIER_VALIDATE', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->oldref = $this->ref;
// Rename directory if dir was a temporary ref
- if (preg_match('/^[\(]?PROV/i', $this->ref))
- {
+ if (preg_match('/^[\(]?PROV/i', $this->ref)) {
// Now we rename also files into index
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'fournisseur/facture/".get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$this->db->escape($this->newref)."'";
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'fournisseur/facture/".get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$this->db->escape($this->ref)."' and entity = ".$conf->entity;
$resql = $this->db->query($sql);
- if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
+ if (!$resql) {
+ $error++; $this->error = $this->db->lasterror();
+ }
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
$oldref = dol_sanitizeFileName($this->ref);
$newref = dol_sanitizeFileName($num);
$dirsource = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$oldref;
$dirdest = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$newref;
- if (!$error && file_exists($dirsource))
- {
+ if (!$error && file_exists($dirsource)) {
dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
- if (@rename($dirsource, $dirdest))
- {
+ if (@rename($dirsource, $dirdest)) {
dol_syslog("Rename ok");
// Rename docs starting with $oldref with $newref
$listoffiles = dol_dir_list($conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
- foreach ($listoffiles as $fileentry)
- {
+ foreach ($listoffiles as $fileentry) {
$dirsource = $fileentry['name'];
$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
$dirsource = $fileentry['path'].'/'.$dirsource;
@@ -1512,15 +1548,13 @@ class FactureFournisseur extends CommonInvoice
}
// Set new ref and define current statut
- if (!$error)
- {
+ if (!$error) {
$this->ref = $num;
$this->statut = self::STATUS_VALIDATED;
//$this->date_validation=$now; this is stored into log table
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
@@ -1548,8 +1582,7 @@ class FactureFournisseur extends CommonInvoice
$error = 0;
- if ($this->statut == self::STATUS_DRAFT)
- {
+ if ($this->statut == self::STATUS_DRAFT) {
dol_syslog(__METHOD__." already draft status", LOG_WARNING);
return 0;
}
@@ -1563,42 +1596,40 @@ class FactureFournisseur extends CommonInvoice
$sql .= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql);
- if ($result)
- {
- if (!$error)
- {
+ if ($result) {
+ if (!$error) {
$this->oldcopy = clone $this;
}
// Si on incremente le produit principal et ses composants a la validation de facture fournisseur, on decremente
- if ($result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL))
- {
+ if ($result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) {
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
$langs->load("agenda");
$cpt = count($this->lines);
- for ($i = 0; $i < $cpt; $i++)
- {
- if ($this->lines[$i]->fk_product > 0)
- {
+ for ($i = 0; $i < $cpt; $i++) {
+ if ($this->lines[$i]->fk_product > 0) {
$mouvP = new MouvementStock($this->db);
$mouvP->origin = &$this;
// We increase stock for product
- if ($this->type == FactureFournisseur::TYPE_CREDIT_NOTE) $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref));
- else $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref));
+ if ($this->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
+ $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref));
+ } else {
+ $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref));
+ }
}
}
}
// Triggers call
- if (!$error && empty($notrigger))
- {
+ if (!$error && empty($notrigger)) {
// Call trigger
$result = $this->call_trigger('BILL_SUPPLIER_UNVALIDATE', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if ($error == 0)
- {
+ if ($error == 0) {
$this->db->commit();
return 1;
} else {
@@ -1652,17 +1683,32 @@ class FactureFournisseur extends CommonInvoice
dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type,$fk_unit", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
- if ($this->statut == self::STATUS_DRAFT)
- {
+ if ($this->statut == self::STATUS_DRAFT) {
// Clean parameters
- if (empty($remise_percent)) $remise_percent = 0;
- if (empty($qty)) $qty = 0;
- if (empty($info_bits)) $info_bits = 0;
- if (empty($rang)) $rang = 0;
- if (empty($ventil)) $ventil = 0;
- if (empty($txtva)) $txtva = 0;
- if (empty($txlocaltax1)) $txlocaltax1 = 0;
- if (empty($txlocaltax2)) $txlocaltax2 = 0;
+ if (empty($remise_percent)) {
+ $remise_percent = 0;
+ }
+ if (empty($qty)) {
+ $qty = 0;
+ }
+ if (empty($info_bits)) {
+ $info_bits = 0;
+ }
+ if (empty($rang)) {
+ $rang = 0;
+ }
+ if (empty($ventil)) {
+ $ventil = 0;
+ }
+ if (empty($txtva)) {
+ $txtva = 0;
+ }
+ if (empty($txlocaltax1)) {
+ $txlocaltax1 = 0;
+ }
+ if (empty($txlocaltax2)) {
+ $txlocaltax2 = 0;
+ }
$remise_percent = price2num($remise_percent);
$qty = price2num($qty);
@@ -1681,15 +1727,12 @@ class FactureFournisseur extends CommonInvoice
$this->db->begin();
- if ($fk_product > 0)
- {
- if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY))
- {
+ if ($fk_product > 0) {
+ if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
// Check quantity is enough
dol_syslog(get_class($this)."::addline we check supplier prices fk_product=".$fk_product." qty=".$qty." ref_supplier=".$ref_supplier);
$prod = new Product($this->db, $fk_product);
- if ($prod->fetch($fk_product) > 0)
- {
+ if ($prod->fetch($fk_product) > 0) {
$product_type = $prod->type;
$label = $prod->label;
$fk_prod_fourn_price = 0;
@@ -1697,16 +1740,17 @@ class FactureFournisseur extends CommonInvoice
// We use 'none' instead of $ref_supplier, because $ref_supplier may not exists anymore. So we will take the first supplier price ok.
// If we want a dedicated supplier price, we must provide $fk_prod_fourn_price.
$result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', ($this->fk_soc ? $this->fk_soc : $this->socid)); // Search on couple $fk_prod_fourn_price/$qty first, then on triplet $qty/$fk_product/$ref_supplier/$this->fk_soc
- if ($result > 0)
- {
- if (empty($pu)) $pu = $prod->fourn_pu; // Unit price supplier price set by get_buyprice
+ if ($result > 0) {
+ if (empty($pu)) {
+ $pu = $prod->fourn_pu; // Unit price supplier price set by get_buyprice
+ }
$ref_supplier = $prod->ref_supplier; // Ref supplier price set by get_buyprice
// is remise percent not keyed but present for the product we add it
- if ($remise_percent == 0 && $prod->remise_percent != 0)
+ if ($remise_percent == 0 && $prod->remise_percent != 0) {
$remise_percent = $prod->remise_percent;
+ }
}
- if ($result == 0) // If result == 0, we failed to found the supplier reference price
- {
+ if ($result == 0) { // If result == 0, we failed to found the supplier reference price
$langs->load("errors");
$this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
$this->db->rollback();
@@ -1715,16 +1759,14 @@ class FactureFournisseur extends CommonInvoice
//$ref = $prod->ref_fourn; // We do not overwrite ref supplier price
return -1;
}
- if ($result == -1)
- {
+ if ($result == -1) {
$langs->load("errors");
$this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
$this->db->rollback();
dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_DEBUG);
return -1;
}
- if ($result < -1)
- {
+ if ($result < -1) {
$this->error = $prod->error;
$this->db->rollback();
dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_ERR);
@@ -1749,8 +1791,7 @@ class FactureFournisseur extends CommonInvoice
// Clean vat code
$reg = array();
$vat_src_code = '';
- if (preg_match('/\((.*)\)/', $txtva, $reg))
- {
+ if (preg_match('/\((.*)\)/', $txtva, $reg)) {
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
@@ -1775,10 +1816,11 @@ class FactureFournisseur extends CommonInvoice
$pu_ht_devise = $tabprice[19];
// Check parameters
- if ($type < 0) return -1;
+ if ($type < 0) {
+ return -1;
+ }
- if ($rang < 0)
- {
+ if ($rang < 0) {
$rangmax = $this->line_max();
$rang = $rangmax + 1;
}
@@ -1837,15 +1879,15 @@ class FactureFournisseur extends CommonInvoice
}
$result = $this->line->insert($notrigger);
- if ($result > 0)
- {
+ if ($result > 0) {
// Reorder if child line
- if (!empty($fk_parent_line)) $this->line_order(true, 'DESC');
+ if (!empty($fk_parent_line)) {
+ $this->line_order(true, 'DESC');
+ }
// Mise a jour informations denormalisees au niveau de la facture meme
$result = $this->update_price(1, 'auto', 0, $this->thirdparty); // The addline method is designed to add line from user input so total calculation with update_price must be done using 'auto' mode.
- if ($result > 0)
- {
+ if ($result > 0) {
$this->db->commit();
return $this->line->id;
} else {
@@ -1902,7 +1944,9 @@ class FactureFournisseur extends CommonInvoice
// Check parameters
//if (! is_numeric($pu) || ! is_numeric($qty)) return -1;
- if ($type < 0) return -1;
+ if ($type < 0) {
+ return -1;
+ }
if ($date_start && $date_end && $date_start > $date_end) {
$langs->load("errors");
@@ -1911,9 +1955,15 @@ class FactureFournisseur extends CommonInvoice
}
// Clean parameters
- if (empty($vatrate)) $vatrate = 0;
- if (empty($txlocaltax1)) $txlocaltax1 = 0;
- if (empty($txlocaltax2)) $txlocaltax2 = 0;
+ if (empty($vatrate)) {
+ $vatrate = 0;
+ }
+ if (empty($txlocaltax1)) {
+ $txlocaltax1 = 0;
+ }
+ if (empty($txlocaltax2)) {
+ $txlocaltax2 = 0;
+ }
$txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2);
@@ -1929,8 +1979,7 @@ class FactureFournisseur extends CommonInvoice
// Clean vat code
$vat_src_code = '';
- if (preg_match('/\((.*)\)/', $vatrate, $reg))
- {
+ if (preg_match('/\((.*)\)/', $vatrate, $reg)) {
$vat_src_code = $reg[1];
$vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate.
}
@@ -1951,10 +2000,11 @@ class FactureFournisseur extends CommonInvoice
$multicurrency_total_ttc = $tabprice[18];
$pu_ht_devise = $tabprice[19];
- if (empty($info_bits)) $info_bits = 0;
+ if (empty($info_bits)) {
+ $info_bits = 0;
+ }
- if ($idproduct)
- {
+ if ($idproduct) {
$product = new Product($this->db);
$result = $product->fetch($idproduct);
$product_type = $product->type;
@@ -2046,8 +2096,7 @@ class FactureFournisseur extends CommonInvoice
dol_syslog(get_class($this)."::deleteline", LOG_DEBUG);
$result = $this->db->query($sql);
- if (!$result)
- {
+ if (!$result) {
$this->error = $this->db->error();
$this->db->rollback();
return -2;
@@ -2068,8 +2117,7 @@ class FactureFournisseur extends CommonInvoice
} else {
$res = $this->update_price();
- if ($res > 0)
- {
+ if ($res > 0) {
$this->db->commit();
return 1;
} else {
@@ -2095,26 +2143,21 @@ class FactureFournisseur extends CommonInvoice
$sql .= ' WHERE c.rowid = '.$id;
$result = $this->db->query($sql);
- if ($result)
- {
- if ($this->db->num_rows($result))
- {
+ if ($result) {
+ if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
- if ($obj->fk_user_author)
- {
+ if ($obj->fk_user_author) {
$cuser = new User($this->db);
$cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser;
}
- if ($obj->fk_user_valid)
- {
+ if ($obj->fk_user_valid) {
$vuser = new User($this->db);
$vuser->fetch($obj->fk_user_valid);
$this->user_validation = $vuser;
}
- 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;
@@ -2155,15 +2198,15 @@ class FactureFournisseur extends CommonInvoice
$sql .= " AND f.paye = 0"; // Pas classee payee completement
$sql .= " AND pf.fk_paiementfourn IS NULL"; // Aucun paiement deja fait
$sql .= " AND ff.fk_statut IS NULL"; // Renvoi vrai si pas facture de remplacement
- if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid;
+ if ($socid > 0) {
+ $sql .= " AND f.fk_soc = ".$socid;
+ }
$sql .= " ORDER BY f.ref";
dol_syslog(get_class($this)."::list_replacable_supplier_invoices", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
- while ($obj = $this->db->fetch_object($resql))
- {
+ if ($resql) {
+ while ($obj = $this->db->fetch_object($resql)) {
$return[$obj->rowid] = array(
'id' => $obj->rowid,
'ref' => $obj->ref,
@@ -2203,20 +2246,23 @@ class FactureFournisseur extends CommonInvoice
$sql .= " AND NOT EXISTS (SELECT rowid from ".MAIN_DB_PREFIX."facture_fourn as ff WHERE f.rowid = ff.fk_facture_source";
$sql .= " AND ff.type=".self::TYPE_REPLACEMENT.")";
$sql .= " AND f.type != ".self::TYPE_CREDIT_NOTE; // Type non 2 si facture non avoir
- if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid;
+ if ($socid > 0) {
+ $sql .= " AND f.fk_soc = ".$socid;
+ }
$sql .= " ORDER BY f.ref";
dol_syslog(get_class($this)."::list_qualified_avoir_supplier_invoices", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
- while ($obj = $this->db->fetch_object($resql))
- {
+ if ($resql) {
+ while ($obj = $this->db->fetch_object($resql)) {
$qualified = 0;
- if ($obj->fk_statut == self::STATUS_VALIDATED) $qualified = 1;
- if ($obj->fk_statut == self::STATUS_CLOSED) $qualified = 1;
- if ($qualified)
- {
+ if ($obj->fk_statut == self::STATUS_VALIDATED) {
+ $qualified = 1;
+ }
+ if ($obj->fk_statut == self::STATUS_CLOSED) {
+ $qualified = 1;
+ }
+ if ($qualified) {
$paymentornot = ($obj->fk_paiementfourn ? 1 : 0);
$return[$obj->rowid] = array('ref'=>$obj->ref, 'status'=>$obj->fk_statut, 'type'=>$obj->type, 'paye'=>$obj->paye, 'paymentornot'=>$paymentornot);
}
@@ -2243,16 +2289,21 @@ class FactureFournisseur extends CommonInvoice
$sql = 'SELECT ff.rowid, ff.date_lim_reglement as datefin, ff.fk_statut';
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as ff';
- 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 ff.paye=0';
$sql .= ' AND ff.fk_statut > 0';
$sql .= " AND ff.entity = ".$conf->entity;
- if ($user->socid) $sql .= ' AND ff.fk_soc = '.$user->socid;
- if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND ff.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
+ if ($user->socid) {
+ $sql .= ' AND ff.fk_soc = '.$user->socid;
+ }
+ if (!$user->rights->societe->client->voir && !$user->socid) {
+ $sql .= " AND ff.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
+ }
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$langs->load("bills");
$now = dol_now();
@@ -2266,8 +2317,7 @@ class FactureFournisseur extends CommonInvoice
$facturestatic = new FactureFournisseur($this->db);
- while ($obj = $this->db->fetch_object($resql))
- {
+ while ($obj = $this->db->fetch_object($resql)) {
$response->nbtodo++;
$facturestatic->date_echeance = $this->db->jdate($obj->datefin);
@@ -2307,56 +2357,84 @@ class FactureFournisseur extends CommonInvoice
$result = '';
- if ($option == 'withdraw') $url = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$this->id.'&type=bank-transfer';
- elseif ($option == 'document') $url = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$this->id;
- else $url = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$this->id;
+ if ($option == 'withdraw') {
+ $url = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$this->id.'&type=bank-transfer';
+ } elseif ($option == 'document') {
+ $url = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$this->id;
+ } else {
+ $url = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$this->id;
+ }
- if ($short) return $url;
+ if ($short) {
+ return $url;
+ }
- if ($option !== 'nolink')
- {
+ if ($option !== 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
- if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
- if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
}
$picto = $this->picto;
- if ($this->type == self::TYPE_REPLACEMENT) $picto .= 'r'; // Replacement invoice
- if ($this->type == self::TYPE_CREDIT_NOTE) $picto .= 'a'; // Credit note
- if ($this->type == self::TYPE_DEPOSIT) $picto .= 'd'; // Deposit invoice
+ if ($this->type == self::TYPE_REPLACEMENT) {
+ $picto .= 'r'; // Replacement invoice
+ }
+ if ($this->type == self::TYPE_CREDIT_NOTE) {
+ $picto .= 'a'; // Credit note
+ }
+ if ($this->type == self::TYPE_DEPOSIT) {
+ $picto .= 'd'; // Deposit invoice
+ }
$label = img_picto('', $this->picto).' '.$langs->trans("SupplierInvoice").' ';
- if ($this->type == self::TYPE_REPLACEMENT) $label = ''.$langs->transnoentitiesnoconv("InvoiceReplace").' ';
- elseif ($this->type == self::TYPE_CREDIT_NOTE) $label = ''.$langs->transnoentitiesnoconv("CreditNote").' ';
- elseif ($this->type == self::TYPE_DEPOSIT) $label = ''.$langs->transnoentitiesnoconv("Deposit").' ';
- if (!empty($this->ref))
+ if ($this->type == self::TYPE_REPLACEMENT) {
+ $label = ''.$langs->transnoentitiesnoconv("InvoiceReplace").' ';
+ } elseif ($this->type == self::TYPE_CREDIT_NOTE) {
+ $label = ''.$langs->transnoentitiesnoconv("CreditNote").' ';
+ } elseif ($this->type == self::TYPE_DEPOSIT) {
+ $label = ''.$langs->transnoentitiesnoconv("Deposit").' ';
+ }
+ if (!empty($this->ref)) {
$label .= ''.$langs->trans('Ref').': '.$this->ref;
- if (!empty($this->ref_supplier))
+ }
+ if (!empty($this->ref_supplier)) {
$label .= ''.$langs->trans('RefSupplier').': '.$this->ref_supplier;
- if (!empty($this->label))
+ }
+ if (!empty($this->label)) {
$label .= ''.$langs->trans('Label').': '.$this->label;
- if (!empty($this->date))
+ }
+ if (!empty($this->date)) {
$label .= ''.$langs->trans('Date').': '.dol_print_date($this->date, 'day');
- if (!empty($this->total_ht))
+ }
+ if (!empty($this->total_ht)) {
$label .= ''.$langs->trans('AmountHT').': '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
- if (!empty($this->total_tva))
+ }
+ if (!empty($this->total_tva)) {
$label .= ''.$langs->trans('AmountVAT').': '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
- if (!empty($this->total_ttc))
+ }
+ if (!empty($this->total_ttc)) {
$label .= ''.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
- if ($moretitle) $label .= ' - '.$moretitle;
+ }
+ if ($moretitle) {
+ $label .= ' - '.$moretitle;
+ }
if (isset($this->statut) && isset($this->alreadypaid)) {
$label .= ''.$langs->trans("Status").": ".$this->getLibStatut(5, $this->alreadypaid);
}
$ref = $this->ref;
- if (empty($ref)) $ref = $this->id;
+ if (empty($ref)) {
+ $ref = $this->id;
+ }
$linkclose = '';
- if (empty($notooltip))
- {
- if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
- {
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowSupplierInvoice");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
@@ -2369,15 +2447,17 @@ class FactureFournisseur extends CommonInvoice
$linkend = ' ';
$result .= $linkstart;
- if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
- if ($withpicto != 2) $result .= ($max ?dol_trunc($ref, $max) : $ref);
+ if ($withpicto) {
+ $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ if ($withpicto != 2) {
+ $result .= ($max ?dol_trunc($ref, $max) : $ref);
+ }
$result .= $linkend;
- if ($addlinktonotes)
- {
+ if ($addlinktonotes) {
$txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
- if ($txttoshow)
- {
+ if ($txttoshow) {
$notetoshow = $langs->trans("ViewPrivateNote").': '.dol_string_nohtmltag($txttoshow, 1);
$result .= ' ';
$result .= '';
@@ -2406,7 +2486,9 @@ class FactureFournisseur extends CommonInvoice
$langs->load("orders");
// Clean parameters (if not defined or using deprecated value)
- if (empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER)) $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER = 'mod_facture_fournisseur_cactus';
+ if (empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER)) {
+ $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER = 'mod_facture_fournisseur_cactus';
+ }
$mybool = false;
@@ -2432,8 +2514,7 @@ class FactureFournisseur extends CommonInvoice
$numref = "";
$numref = $obj->getNumRef($soc, $this, $mode);
- if ($numref != "")
- {
+ if ($numref != "") {
return $numref;
} else {
$this->error = $obj->error;
@@ -2467,12 +2548,10 @@ class FactureFournisseur extends CommonInvoice
$sql .= $this->db->plimit(100);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num_prods = $this->db->num_rows($resql);
$i = 0;
- while ($i < $num_prods)
- {
+ while ($i < $num_prods) {
$i++;
$row = $this->db->fetch_row($resql);
$prodids[$i] = $row[0];
@@ -2496,13 +2575,11 @@ class FactureFournisseur extends CommonInvoice
$this->multicurrency_tx = 1;
$this->multicurrency_code = $conf->currency;
- if (empty($option) || $option != 'nolines')
- {
+ if (empty($option) || $option != 'nolines') {
// Lines
$nbp = 5;
$xnbp = 0;
- while ($xnbp < $nbp)
- {
+ while ($xnbp < $nbp) {
$line = new SupplierInvoiceLine($this->db);
$line->desc = $langs->trans("Description")." ".$xnbp;
$line->qty = 1;
@@ -2512,8 +2589,7 @@ class FactureFournisseur extends CommonInvoice
$line->tva_tx = 19.6;
$line->localtax1_tx = 0;
$line->localtax2_tx = 0;
- if ($xnbp == 2)
- {
+ if ($xnbp == 2) {
$line->total_ht = 50;
$line->total_ttc = 59.8;
$line->total_tva = 9.8;
@@ -2525,8 +2601,7 @@ class FactureFournisseur extends CommonInvoice
$line->remise_percent = 0;
}
- if ($num_prods > 0)
- {
+ if ($num_prods > 0) {
$prodid = mt_rand(1, $num_prods);
$line->fk_product = $prodids[$prodid];
}
@@ -2566,8 +2641,7 @@ class FactureFournisseur extends CommonInvoice
$sql = "SELECT count(f.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
- 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";
@@ -2575,10 +2649,8 @@ class FactureFournisseur extends CommonInvoice
$sql .= " ".$clause." f.entity = ".$conf->entity;
$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["supplier_invoices"] = $obj->nb;
}
$this->db->free($resql);
@@ -2629,10 +2701,8 @@ class FactureFournisseur extends CommonInvoice
$object->close_note = '';
// Loop on each line of new invoice
- foreach ($object->lines as $i => $line)
- {
- if (isset($object->lines[$i]->info_bits) && ($object->lines[$i]->info_bits & 0x02) == 0x02) // We do not clone line of discounts
- {
+ foreach ($object->lines as $i => $line) {
+ if (isset($object->lines[$i]->info_bits) && ($object->lines[$i]->info_bits & 0x02) == 0x02) { // We do not clone line of discounts
unset($object->lines[$i]);
}
}
@@ -2642,22 +2712,19 @@ class FactureFournisseur extends CommonInvoice
$result = $object->create($user);
// Other options
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $object->error;
$this->errors = $object->errors;
$error++;
}
- if (!$error)
- {
+ if (!$error) {
}
unset($object->context['createfromclone']);
// End
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return $object->id;
} else {
@@ -2685,18 +2752,15 @@ class FactureFournisseur extends CommonInvoice
$outputlangs->load("products");
// Set the model on the model name to use
- if (empty($modele))
- {
- if (!empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF))
- {
+ if (empty($modele)) {
+ if (!empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) {
$modele = $conf->global->INVOICE_SUPPLIER_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_invoice/doc/";
@@ -2764,7 +2828,9 @@ class FactureFournisseur extends CommonInvoice
$resql = $this->db->query($sql);
if (!empty($resql)) {
$obj = $this->db->fetch_object($resql);
- if (!empty($obj->fk_invoice_supplier)) $isUsed = true;
+ if (!empty($obj->fk_invoice_supplier)) {
+ $isUsed = true;
+ }
}
return $isUsed;
@@ -3111,11 +3177,9 @@ class SupplierInvoiceLine extends CommonObjectLine
$this->deleteObjectLinked();
// Remove extrafields
- if (!$error)
- {
+ if (!$error) {
$result = $this->deleteExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
@@ -3133,8 +3197,7 @@ class SupplierInvoiceLine extends CommonObjectLine
}
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
@@ -3157,22 +3220,31 @@ class SupplierInvoiceLine extends CommonObjectLine
$qty = price2num($this->qty);
// Check parameters
- if (empty($this->qty)) $this->qty = 0;
+ if (empty($this->qty)) {
+ $this->qty = 0;
+ }
if ($this->product_type < 0) {
return -1;
}
// Clean parameters
- if (empty($this->remise_percent)) $this->remise_percent = 0;
- if (empty($this->tva_tx)) $this->tva_tx = 0;
- if (empty($this->localtax1_tx)) $this->localtax1_tx = 0;
- if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
+ if (empty($this->remise_percent)) {
+ $this->remise_percent = 0;
+ }
+ if (empty($this->tva_tx)) {
+ $this->tva_tx = 0;
+ }
+ if (empty($this->localtax1_tx)) {
+ $this->localtax1_tx = 0;
+ }
+ if (empty($this->localtax2_tx)) {
+ $this->localtax2_tx = 0;
+ }
$this->db->begin();
- if (empty($this->fk_product))
- {
+ if (empty($this->fk_product)) {
$fk_product = "null";
} else {
$fk_product = $this->fk_product;
@@ -3229,17 +3301,14 @@ class SupplierInvoiceLine extends CommonObjectLine
$this->rowid = $this->id;
$error = 0;
- if (!$error)
- {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
global $langs, $user;
// Call trigger
@@ -3275,41 +3344,78 @@ class SupplierInvoiceLine extends CommonObjectLine
// Clean parameters
$this->desc = trim($this->desc);
- if (empty($this->tva_tx)) $this->tva_tx = 0;
- if (empty($this->localtax1_tx)) $this->localtax1_tx = 0;
- if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
- if (empty($this->localtax1_type)) $this->localtax1_type = '0';
- if (empty($this->localtax2_type)) $this->localtax2_type = '0';
- if (empty($this->total_tva)) $this->total_tva = 0;
- if (empty($this->total_localtax1)) $this->total_localtax1 = 0;
- if (empty($this->total_localtax2)) $this->total_localtax2 = 0;
- if (empty($this->rang)) $this->rang = 0;
- if (empty($this->remise_percent)) $this->remise_percent = 0;
- if (empty($this->info_bits)) $this->info_bits = 0;
- if (empty($this->subprice)) $this->subprice = 0;
- if (empty($this->special_code)) $this->special_code = 0;
- if (empty($this->fk_parent_line)) $this->fk_parent_line = 0;
- if (!isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') $this->situation_percent = 100;
+ if (empty($this->tva_tx)) {
+ $this->tva_tx = 0;
+ }
+ if (empty($this->localtax1_tx)) {
+ $this->localtax1_tx = 0;
+ }
+ if (empty($this->localtax2_tx)) {
+ $this->localtax2_tx = 0;
+ }
+ if (empty($this->localtax1_type)) {
+ $this->localtax1_type = '0';
+ }
+ if (empty($this->localtax2_type)) {
+ $this->localtax2_type = '0';
+ }
+ if (empty($this->total_tva)) {
+ $this->total_tva = 0;
+ }
+ if (empty($this->total_localtax1)) {
+ $this->total_localtax1 = 0;
+ }
+ if (empty($this->total_localtax2)) {
+ $this->total_localtax2 = 0;
+ }
+ if (empty($this->rang)) {
+ $this->rang = 0;
+ }
+ if (empty($this->remise_percent)) {
+ $this->remise_percent = 0;
+ }
+ if (empty($this->info_bits)) {
+ $this->info_bits = 0;
+ }
+ if (empty($this->subprice)) {
+ $this->subprice = 0;
+ }
+ if (empty($this->special_code)) {
+ $this->special_code = 0;
+ }
+ if (empty($this->fk_parent_line)) {
+ $this->fk_parent_line = 0;
+ }
+ if (!isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') {
+ $this->situation_percent = 100;
+ }
- if (empty($this->pa_ht)) $this->pa_ht = 0;
- if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice = 0;
- if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht = 0;
- if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva = 0;
- if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc = 0;
+ if (empty($this->pa_ht)) {
+ $this->pa_ht = 0;
+ }
+ if (empty($this->multicurrency_subprice)) {
+ $this->multicurrency_subprice = 0;
+ }
+ if (empty($this->multicurrency_total_ht)) {
+ $this->multicurrency_total_ht = 0;
+ }
+ if (empty($this->multicurrency_total_tva)) {
+ $this->multicurrency_total_tva = 0;
+ }
+ if (empty($this->multicurrency_total_ttc)) {
+ $this->multicurrency_total_ttc = 0;
+ }
// Check parameters
- if ($this->product_type < 0)
- {
+ if ($this->product_type < 0) {
$this->error = 'ErrorProductTypeMustBe0orMore';
return -1;
}
- if (!empty($this->fk_product))
- {
+ if (!empty($this->fk_product)) {
// Check product exists
$result = Product::isExistingObject('product', $this->fk_product);
- if ($result <= 0)
- {
+ if ($result <= 0) {
$this->error = 'ErrorProductIdDoesNotExists';
return -1;
}
@@ -3365,26 +3471,21 @@ class SupplierInvoiceLine extends CommonObjectLine
$sql .= ')';
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
$this->rowid = $this->id; // backward compatibility
- if (!$error)
- {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('LINEBILL_SUPPLIER_CREATE', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->db->rollback();
return -2;
}
@@ -3423,8 +3524,7 @@ class SupplierInvoiceLine extends CommonObjectLine
dol_syslog("FactureFournisseurLigne.class.php::update_total", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->db->commit();
return 1;
} else {
diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php
index 6ae9a3491ab..db2b6dd749a 100644
--- a/htdocs/fourn/class/fournisseur.product.class.php
+++ b/htdocs/fourn/class/fournisseur.product.class.php
@@ -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 {
@@ -936,7 +952,7 @@ class ProductFournisseur extends Product
}
$out .= '