Scrutinizer Auto-Fixes

This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
This commit is contained in:
Scrutinizer Auto-Fixer 2019-11-08 09:53:31 +00:00
parent ad2ff551fa
commit 2ecfe41810
20 changed files with 3667 additions and 3667 deletions

View File

@ -33,8 +33,8 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array('banks', 'categories')); $langs->loadLangs(array('banks', 'categories'));
$action=GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
if (!$user->rights->banque->configurer) if (!$user->rights->banque->configurer)
accessforbidden(); accessforbidden();
@ -92,7 +92,7 @@ print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">'; print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
*/ */
print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Ref").'</td><td colspan="2">'.$langs->trans("Label").'</td>'; print '<td>'.$langs->trans("Ref").'</td><td colspan="2">'.$langs->trans("Label").'</td>';
@ -109,9 +109,9 @@ if ($action != 'edit')
$sql = "SELECT rowid, label"; $sql = "SELECT rowid, label";
$sql.= " FROM ".MAIN_DB_PREFIX."bank_categ"; $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ";
$sql.= " WHERE entity = ".$conf->entity; $sql .= " WHERE entity = ".$conf->entity;
$sql.= " ORDER BY label"; $sql .= " ORDER BY label";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
@ -125,7 +125,7 @@ if ($result)
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td><a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$objp->rowid.'</a></td>'; print '<td><a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$objp->rowid.'</a></td>';
if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid")== $objp->rowid) if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid") == $objp->rowid)
{ {
print "<td colspan=2>"; print "<td colspan=2>";
print '<input type="hidden" name="categid" value="'.$objp->rowid.'">'; print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';

File diff suppressed because it is too large Load Diff

View File

@ -31,12 +31,12 @@ require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("other","compta","banks","bills","companies","product","trips","admin")); $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
$local=GETPOST('localTaxType', 'int'); $local = GETPOST('localTaxType', 'int');
// Date range // Date range
$year=GETPOST("year", "int"); $year = GETPOST("year", "int");
if (empty($year)) if (empty($year))
{ {
$year_current = strftime("%Y", dol_now()); $year_current = strftime("%Y", dol_now());
@ -45,29 +45,29 @@ if (empty($year))
$year_current = $year; $year_current = $year;
$year_start = $year; $year_start = $year;
} }
$date_start=dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear")); $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")); $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
// Quarter // Quarter
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"); $q = GETPOST("q");
if (empty($q)) if (empty($q))
{ {
if (GETPOST("month")) { $date_start=dol_get_first_day($year_start, GETPOST("month"), false); $date_end=dol_get_last_day($year_start, GETPOST("month"), false); } if (GETPOST("month")) { $date_start = dol_get_first_day($year_start, GETPOST("month"), false); $date_end = dol_get_last_day($year_start, GETPOST("month"), false); }
else else
{ {
$date_start=dol_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START, false); $date_start = dol_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START, false);
if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) $date_end=dol_time_plus_duree($date_start, 3, 'm') - 1; if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) $date_end=dol_time_plus_duree($date_start, 1, 'y') - 1; elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) $date_end=dol_time_plus_duree($date_start, 1, 'm') - 1; elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
} }
} }
else 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 == 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 == 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 == 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 == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
} }
} }
@ -77,12 +77,12 @@ if (empty($min)) $min = 0;
// Define modetax (0 or 1) // Define modetax (0 or 1)
// 0=normal, 1=option vat for services is on debit, 2=option on payments for products // 0=normal, 1=option vat for services is on debit, 2=option on payments for products
$modetax = $conf->global->TAX_MODE; $modetax = $conf->global->TAX_MODE;
if (GETPOSTISSET("modetax")) $modetax=GETPOST("modetax", 'int'); if (GETPOSTISSET("modetax")) $modetax = GETPOST("modetax", 'int');
if (empty($modetax)) $modetax=0; if (empty($modetax)) $modetax = 0;
// Security check // Security check
$socid = GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
if ($user->socid) $socid=$user->socid; if ($user->socid) $socid = $user->socid;
$result = restrictedArea($user, 'tax', '', '', 'charges'); $result = restrictedArea($user, 'tax', '', '', 'charges');
if (empty($local)) if (empty($local))
@ -97,72 +97,72 @@ if (empty($local))
* View * View
*/ */
$form=new Form($db); $form = new Form($db);
$company_static=new Societe($db); $company_static = new Societe($db);
$morequerystring=''; $morequerystring = '';
$listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday'); $listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
foreach($listofparams as $param) foreach ($listofparams as $param)
{ {
if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param); if (GETPOST($param) != '') $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
} }
llxHeader('', '', '', '', 0, 0, '', '', $morequerystring); llxHeader('', '', '', '', 0, 0, '', '', $morequerystring);
$name=$langs->transcountry($local==1?"LT1ReportByCustomers":"LT2ReportByCustomers", $mysoc->country_code); $name = $langs->transcountry($local == 1 ? "LT1ReportByCustomers" : "LT2ReportByCustomers", $mysoc->country_code);
$fsearch ='<!-- hidden fields for form -->'; $fsearch = '<!-- hidden fields for form -->';
$fsearch.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; $fsearch .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$fsearch.='<input type="hidden" name="modetax" value="'.$modetax.'">'; $fsearch .= '<input type="hidden" name="modetax" value="'.$modetax.'">';
$fsearch.='<input type="hidden" name="localTaxType" value="'.$local.'">'; $fsearch .= '<input type="hidden" name="localTaxType" value="'.$local.'">';
$fsearch.=$langs->trans("SalesTurnoverMinimum").': '; $fsearch .= $langs->trans("SalesTurnoverMinimum").': ';
$fsearch.='<input type="text" name="min" id="min" value="'.$min.'" size="6">'; $fsearch .= '<input type="text" name="min" id="min" value="'.$min.'" size="6">';
$calc=$conf->global->MAIN_INFO_LOCALTAX_CALC.$local; $calc = $conf->global->MAIN_INFO_LOCALTAX_CALC.$local;
// Affiche en-tete du rapport // Affiche en-tete du rapport
if ($calc==0 || $calc==1) // Calculate on invoice for goods and services if ($calc == 0 || $calc == 1) // Calculate on invoice for goods and services
{ {
$calcmode=$calc==0?$langs->trans("CalcModeLT".$local):$langs->trans("CalcModeLT".$local."Rec"); $calcmode = $calc == 0 ? $langs->trans("CalcModeLT".$local) : $langs->trans("CalcModeLT".$local."Rec");
$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')'; $calcmode .= '<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')';
$period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded"); if (!empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
$description.=$fsearch; $description .= $fsearch;
$description.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')'; $description .= '<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')';
$builddate=dol_now(); $builddate = dol_now();
$elementcust=$langs->trans("CustomersInvoices"); $elementcust = $langs->trans("CustomersInvoices");
$productcust=$langs->trans("Description"); $productcust = $langs->trans("Description");
$amountcust=$langs->trans("AmountHT"); $amountcust = $langs->trans("AmountHT");
$elementsup=$langs->trans("SuppliersInvoices"); $elementsup = $langs->trans("SuppliersInvoices");
$productsup=$langs->trans("Description"); $productsup = $langs->trans("Description");
$amountsup=$langs->trans("AmountHT"); $amountsup = $langs->trans("AmountHT");
} }
if ($calc==2) // Invoice for goods, payment for services if ($calc == 2) // Invoice for goods, payment for services
{ {
$calcmode=$langs->trans("CalcModeLT2Debt"); $calcmode = $langs->trans("CalcModeLT2Debt");
$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')'; $calcmode .= '<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')';
$period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded"); if (!empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
$description.=$fsearch; $description .= $fsearch;
$description.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')'; $description .= '<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')';
$builddate=dol_now(); $builddate = dol_now();
$elementcust=$langs->trans("CustomersInvoices"); $elementcust = $langs->trans("CustomersInvoices");
$productcust=$langs->trans("Description"); $productcust = $langs->trans("Description");
$amountcust=$langs->trans("AmountHT"); $amountcust = $langs->trans("AmountHT");
$elementsup=$langs->trans("SuppliersInvoices"); $elementsup = $langs->trans("SuppliersInvoices");
$productsup=$langs->trans("Description"); $productsup = $langs->trans("Description");
$amountsup=$langs->trans("AmountHT"); $amountsup = $langs->trans("AmountHT");
} }
report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode); report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
$vatcust=$langs->transcountry($local==1?"LT1":"LT2", $mysoc->country_code); $vatcust = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code);
$vatsup=$langs->transcountry($local==1?"LT1":"LT2", $mysoc->country_code); $vatsup = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code);
// IRPF that the customer has retained me // IRPF that the customer has retained me
if($calc ==0 || $calc == 2) if ($calc == 0 || $calc == 2)
{ {
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
@ -185,20 +185,20 @@ if($calc ==0 || $calc == 2)
// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('externalbalance')); $hookmanager->initHooks(array('externalbalance'));
$reshook=$hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if (is_array($coll_list)) if (is_array($coll_list))
{ {
$total = 0; $totalamount = 0; $total = 0; $totalamount = 0;
$i = 1; $i = 1;
foreach($coll_list as $coll) foreach ($coll_list as $coll)
{ {
if(($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local==1?$coll->localtax1:$coll->localtax2) !=0) if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0)
{ {
$intra = str_replace($find, $replace, $coll->tva_intra); $intra = str_replace($find, $replace, $coll->tva_intra);
if(empty($intra)) if (empty($intra))
{ {
if($coll->assuj == '1') if ($coll->assuj == '1')
{ {
$intra = $langs->trans('Unknown'); $intra = $langs->trans('Unknown');
} }
@ -209,16 +209,16 @@ if($calc ==0 || $calc == 2)
} }
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td class="nowrap">'.$i."</td>"; print '<td class="nowrap">'.$i."</td>";
$company_static->id=$coll->socid; $company_static->id = $coll->socid;
$company_static->name=$coll->name; $company_static->name = $coll->name;
print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>'; print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
$find = array(' ','.'); $find = array(' ', '.');
$replace = array('',''); $replace = array('', '');
print '<td class="nowrap">'.$intra.'</td>'; print '<td class="nowrap">'.$intra.'</td>';
print '<td class="nowrap right">'.price($coll->amount).'</td>'; print '<td class="nowrap right">'.price($coll->amount).'</td>';
print '<td class="nowrap right">'.price($local==1?$coll->localtax1:$coll->localtax2).'</td>'; print '<td class="nowrap right">'.price($local == 1 ? $coll->localtax1 : $coll->localtax2).'</td>';
$totalamount = $totalamount + $coll->amount; $totalamount = $totalamount + $coll->amount;
$total = $total + ($local==1?$coll->localtax1:$coll->localtax2); $total = $total + ($local == 1 ? $coll->localtax1 : $coll->localtax2);
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
} }
@ -243,7 +243,7 @@ if($calc ==0 || $calc == 2)
} }
// IRPF I retained my supplier // IRPF I retained my supplier
if($calc ==0 || $calc == 1){ if ($calc == 0 || $calc == 1) {
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td class="left">'.$langs->trans("Num")."</td>"; print '<td class="left">'.$langs->trans("Num")."</td>";
@ -253,25 +253,25 @@ if($calc ==0 || $calc == 1){
print '<td class="right">'.$vatsup.'</td>'; print '<td class="right">'.$vatsup.'</td>';
print "</tr>\n"; print "</tr>\n";
$company_static=new Societe($db); $company_static = new Societe($db);
$coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'buy'); $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'buy');
$parameters["direction"] = 'buy'; $parameters["direction"] = 'buy';
$parameters["type"] = 'localtax'.$local; $parameters["type"] = 'localtax'.$local;
$reshook=$hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if (is_array($coll_list)) if (is_array($coll_list))
{ {
$total = 0; $totalamount = 0; $total = 0; $totalamount = 0;
$i = 1; $i = 1;
foreach($coll_list as $coll) foreach ($coll_list as $coll)
{ {
if(($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local==1?$coll->localtax1:$coll->localtax2) != 0) if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0)
{ {
$intra = str_replace($find, $replace, $coll->tva_intra); $intra = str_replace($find, $replace, $coll->tva_intra);
if(empty($intra)) if (empty($intra))
{ {
if($coll->assuj == '1') if ($coll->assuj == '1')
{ {
$intra = $langs->trans('Unknown'); $intra = $langs->trans('Unknown');
} }
@ -282,16 +282,16 @@ if($calc ==0 || $calc == 1){
} }
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td class="nowrap">'.$i."</td>"; print '<td class="nowrap">'.$i."</td>";
$company_static->id=$coll->socid; $company_static->id = $coll->socid;
$company_static->name=$coll->name; $company_static->name = $coll->name;
print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>'; print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
$find = array(' ','.'); $find = array(' ', '.');
$replace = array('',''); $replace = array('', '');
print '<td class="nowrap">'.$intra."</td>"; print '<td class="nowrap">'.$intra."</td>";
print '<td class="nowrap right">'.price($coll->amount).'</td>'; print '<td class="nowrap right">'.price($coll->amount).'</td>';
print '<td class="nowrap right">'.price($local==1?$coll->localtax1:$coll->localtax2).'</td>'; print '<td class="nowrap right">'.price($local == 1 ? $coll->localtax1 : $coll->localtax2).'</td>';
$totalamount = $totalamount + $coll->amount; $totalamount = $totalamount + $coll->amount;
$total = $total + ($local==1?$coll->localtax1:$coll->localtax2); $total = $total + ($local == 1 ? $coll->localtax1 : $coll->localtax2);
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
} }
@ -317,13 +317,13 @@ if($calc ==0 || $calc == 1){
} }
} }
if($calc ==0){ if ($calc == 0) {
// Total to pay // Total to pay
print '<br><br>'; print '<br><br>';
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
$diff = $x_coll_sum - $x_paye_sum ; $diff = $x_coll_sum - $x_paye_sum;
print '<tr class="liste_total">'; print '<tr class="liste_total">';
print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>'; print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q ? ', '.$langs->trans("Quadri").' '.$q : '').'</td>';
print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n"; print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n";
print "</tr>\n"; print "</tr>\n";
} }

View File

@ -31,7 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.p
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array('banks', 'categories','bills','withdrawals')); $langs->loadLangs(array('banks', 'categories', 'bills', 'withdrawals'));
if (!$user->rights->prelevement->bons->lire) if (!$user->rights->prelevement->bons->lire)
accessforbidden(); accessforbidden();
@ -46,7 +46,7 @@ $ref = GETPOST('ref', 'alpha');
$socid = GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
// Load variable for pagination // Load variable for pagination
$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'alpha'); $sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOST('page', 'int'); $page = GETPOST('page', 'int');
@ -55,15 +55,15 @@ $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (! $sortfield) $sortfield='pl.fk_soc'; if (!$sortfield) $sortfield = 'pl.fk_soc';
if (! $sortorder) $sortorder='DESC'; if (!$sortorder) $sortorder = 'DESC';
$object = new BonPrelevement($db, ""); $object = new BonPrelevement($db, "");
// Load object // Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
$hookmanager->initHooks(array('directdebitprevcard','globalcard')); $hookmanager->initHooks(array('directdebitprevcard', 'globalcard'));
/* /*
* Actions * Actions
@ -75,9 +75,9 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
if (empty($reshook)) if (empty($reshook))
{ {
if ( $action == 'confirm_delete' ) if ($action == 'confirm_delete')
{ {
$res=$object->delete($user); $res = $object->delete($user);
if ($res > 0) if ($res > 0)
{ {
header("Location: index.php"); header("Location: index.php");
@ -86,9 +86,9 @@ if (empty($reshook))
} }
// Seems to no be used and replaced with $action == 'infocredit' // Seems to no be used and replaced with $action == 'infocredit'
if ( $action == 'confirm_credite' && GETPOST('confirm', 'alpha') == 'yes') if ($action == 'confirm_credite' && GETPOST('confirm', 'alpha') == 'yes')
{ {
$res=$object->set_credite(); $res = $object->set_credite();
if ($res >= 0) if ($res >= 0)
{ {
header("Location: card.php?id=".$id); header("Location: card.php?id=".$id);
@ -160,7 +160,7 @@ if ($id > 0 || $ref)
$head = prelevement_prepare_head($object); $head = prelevement_prepare_head($object);
dol_fiche_head($head, 'prelevement', $langs->trans("WithdrawalsReceipts"), -1, 'payment'); dol_fiche_head($head, 'prelevement', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
if (GETPOST('error', 'alpha')!='') if (GETPOST('error', 'alpha') != '')
{ {
print '<div class="error">'.$object->getErrorString(GETPOST('error', 'alpha')).'</div>'; print '<div class="error">'.$object->getErrorString(GETPOST('error', 'alpha')).'</div>';
} }
@ -190,7 +190,7 @@ if ($id > 0 || $ref)
print '</tr>'; print '</tr>';
*/ */
if($object->date_trans <> 0) if ($object->date_trans <> 0)
{ {
$muser = new User($db); $muser = new User($db);
$muser->fetch($object->user_trans); $muser->fetch($object->user_trans);
@ -202,7 +202,7 @@ if ($id > 0 || $ref)
print $object->methodes_trans[$object->method_trans]; print $object->methodes_trans[$object->method_trans];
print '</td></tr>'; print '</td></tr>';
} }
if($object->date_credit <> 0) if ($object->date_credit <> 0)
{ {
print '<tr><td>'.$langs->trans('CreditDate').'</td><td>'; print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
print dol_print_date($object->date_credit, 'day'); print dol_print_date($object->date_credit, 'day');
@ -217,7 +217,7 @@ if ($id > 0 || $ref)
print '<table class="border centpercent">'; print '<table class="border centpercent">';
$acc = new Account($db); $acc = new Account($db);
$result=$acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT); $result = $acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT);
print '<tr><td class="titlefield">'; print '<tr><td class="titlefield">';
print $langs->trans("BankToReceiveWithdraw"); print $langs->trans("BankToReceiveWithdraw");
@ -244,7 +244,7 @@ if ($id > 0 || $ref)
// Confirmation to delete // Confirmation to delete
if ($action == 'delete') if ($action == 'delete')
{ {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('Delete'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Delete'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
} }
// Call Hook formConfirm // Call Hook formConfirm
@ -257,7 +257,7 @@ if ($id > 0 || $ref)
print $formconfirm; print $formconfirm;
if (empty($object->date_trans) && $user->rights->prelevement->bons->send && $action=='settransmitted') if (empty($object->date_trans) && $user->rights->prelevement->bons->send && $action == 'settransmitted')
{ {
print '<form method="post" name="userfile" action="card.php?id='.$object->id.'" enctype="multipart/form-data">'; print '<form method="post" name="userfile" action="card.php?id='.$object->id.'" enctype="multipart/form-data">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -281,7 +281,7 @@ if ($id > 0 || $ref)
print '<br>'; print '<br>';
} }
if (! empty($object->date_trans) && $object->date_credit == 0 && $user->rights->prelevement->bons->credit && $action=='setcredited') if (!empty($object->date_trans) && $object->date_credit == 0 && $user->rights->prelevement->bons->credit && $action == 'setcredited')
{ {
print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">'; print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -310,7 +310,7 @@ if ($id > 0 || $ref)
print "<a class=\"butAction\" href=\"card.php?action=settransmitted&id=".$object->id."\">".$langs->trans("SetToStatusSent")."</a>"; print "<a class=\"butAction\" href=\"card.php?action=settransmitted&id=".$object->id."\">".$langs->trans("SetToStatusSent")."</a>";
} }
if (! empty($object->date_trans) && $object->date_credit == 0) if (!empty($object->date_trans) && $object->date_credit == 0)
{ {
print "<a class=\"butAction\" href=\"card.php?action=setcredited&id=".$object->id."\">".$langs->trans("ClassCredited")."</a>"; print "<a class=\"butAction\" href=\"card.php?action=setcredited&id=".$object->id."\">".$langs->trans("ClassCredited")."</a>";
} }
@ -321,22 +321,22 @@ if ($id > 0 || $ref)
} }
$ligne=new LignePrelevement($db, $user); $ligne = new LignePrelevement($db, $user);
/* /*
* Lines into withdraw request * Lines into withdraw request
*/ */
$sql = "SELECT pl.rowid, pl.statut, pl.amount,"; $sql = "SELECT pl.rowid, pl.statut, pl.amount,";
$sql.= " s.rowid as socid, s.nom as name"; $sql .= " s.rowid as socid, s.nom as name";
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
$sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb"; $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
$sql.= ", ".MAIN_DB_PREFIX."societe as s"; $sql .= ", ".MAIN_DB_PREFIX."societe as s";
$sql.= " WHERE pl.fk_prelevement_bons = ".$id; $sql .= " WHERE pl.fk_prelevement_bons = ".$id;
$sql.= " AND pl.fk_prelevement_bons = pb.rowid"; $sql .= " AND pl.fk_prelevement_bons = pb.rowid";
$sql.= " AND pb.entity = ".$conf->entity; $sql .= " AND pb.entity = ".$conf->entity;
$sql.= " AND pl.fk_soc = s.rowid"; $sql .= " AND pl.fk_soc = s.rowid";
if ($socid) $sql.= " AND s.rowid = ".$socid; if ($socid) $sql .= " AND s.rowid = ".$socid;
$sql.= $db->order($sortfield, $sortorder); $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records // Count total nb of records
$nbtotalofrecords = ''; $nbtotalofrecords = '';
@ -351,7 +351,7 @@ if ($id > 0 || $ref)
} }
} }
$sql.= $db->plimit($limit+1, $offset); $sql .= $db->plimit($limit + 1, $offset);
$result = $db->query($sql); $result = $db->query($sql);
@ -364,7 +364,7 @@ if ($id > 0 || $ref)
print_barre_liste($langs->trans("Lines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, ''); print_barre_liste($langs->trans("Lines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">'; print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print_liste_field_titre("Lines", $_SERVER["PHP_SELF"], "pl.rowid", '', $urladd); print_liste_field_titre("Lines", $_SERVER["PHP_SELF"], "pl.rowid", '', $urladd);
@ -389,7 +389,7 @@ if ($id > 0 || $ref)
print sprintf("%06s", $obj->rowid); print sprintf("%06s", $obj->rowid);
print '</a></td>'; print '</a></td>';
$thirdparty=new Societe($db); $thirdparty = new Societe($db);
$thirdparty->fetch($obj->socid); $thirdparty->fetch($obj->socid);
print '<td>'; print '<td>';
print $thirdparty->getNomUrl(1); print $thirdparty->getNomUrl(1);

View File

@ -32,7 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("banks","categories",'withdrawals','bills')); $langs->loadLangs(array("banks", "categories", 'withdrawals', 'bills'));
// Securite acces client // Securite acces client
if ($user->socid > 0) accessforbidden(); if ($user->socid > 0) accessforbidden();
@ -42,7 +42,7 @@ $prev_id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha'); $ref = GETPOST('ref', 'alpha');
// Load variable for pagination // Load variable for pagination
$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'alpha'); $sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOST('page', 'int'); $page = GETPOST('page', 'int');
@ -88,7 +88,7 @@ if ($prev_id > 0 || $ref)
print '</tr>'; print '</tr>';
*/ */
if($object->date_trans <> 0) if ($object->date_trans <> 0)
{ {
$muser = new User($db); $muser = new User($db);
$muser->fetch($object->user_trans); $muser->fetch($object->user_trans);
@ -100,7 +100,7 @@ if ($prev_id > 0 || $ref)
print $object->methodes_trans[$object->method_trans]; print $object->methodes_trans[$object->method_trans];
print '</td></tr>'; print '</td></tr>';
} }
if($object->date_credit <> 0) if ($object->date_credit <> 0)
{ {
print '<tr><td>'.$langs->trans('CreditDate').'</td><td>'; print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
print dol_print_date($object->date_credit, 'day'); print dol_print_date($object->date_credit, 'day');
@ -115,7 +115,7 @@ if ($prev_id > 0 || $ref)
print '<table class="border centpercent">'; print '<table class="border centpercent">';
$acc = new Account($db); $acc = new Account($db);
$result=$acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT); $result = $acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT);
print '<tr><td class="titlefield">'; print '<tr><td class="titlefield">';
print $langs->trans("BankToReceiveWithdraw"); print $langs->trans("BankToReceiveWithdraw");
@ -148,20 +148,20 @@ $rej = new RejetPrelevement($db, $user);
* List errors * List errors
*/ */
$sql = "SELECT pl.rowid, pl.amount, pl.statut"; $sql = "SELECT pl.rowid, pl.amount, pl.statut";
$sql.= " , s.rowid as socid, s.nom as name"; $sql .= " , s.rowid as socid, s.nom as name";
$sql.= " , pr.motif, pr.afacturer, pr.fk_facture"; $sql .= " , pr.motif, pr.afacturer, pr.fk_facture";
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
$sql.= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl"; $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
$sql.= " , ".MAIN_DB_PREFIX."societe as s"; $sql .= " , ".MAIN_DB_PREFIX."societe as s";
$sql.= " , ".MAIN_DB_PREFIX."prelevement_rejet as pr"; $sql .= " , ".MAIN_DB_PREFIX."prelevement_rejet as pr";
$sql.= " WHERE p.rowid=".$object->id; $sql .= " WHERE p.rowid=".$object->id;
$sql.= " AND pl.fk_prelevement_bons = p.rowid"; $sql .= " AND pl.fk_prelevement_bons = p.rowid";
$sql.= " AND p.entity = ".$conf->entity; $sql .= " AND p.entity = ".$conf->entity;
$sql.= " AND pl.fk_soc = s.rowid"; $sql .= " AND pl.fk_soc = s.rowid";
$sql.= " AND pl.statut = 3 "; $sql .= " AND pl.statut = 3 ";
$sql.= " AND pr.fk_prelevement_lignes = pl.rowid"; $sql .= " AND pr.fk_prelevement_lignes = pl.rowid";
if ($socid) $sql.= " AND s.rowid = ".$socid; if ($socid) $sql .= " AND s.rowid = ".$socid;
$sql.= " ORDER BY pl.amount DESC"; $sql .= " ORDER BY pl.amount DESC";
// Count total nb of records // Count total nb of records
$nbtotalofrecords = ''; $nbtotalofrecords = '';
@ -176,7 +176,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
} }
} }
$sql.= $db->plimit($limit+1, $offset); $sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
@ -186,7 +186,7 @@ if ($resql)
print_barre_liste($langs->trans("Rejects"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, ''); print_barre_liste($langs->trans("Rejects"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
print"\n<!-- debut table -->\n"; print"\n<!-- debut table -->\n";
print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">'; print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Line").'</td><td>'.$langs->trans("ThirdParty").'</td><td class="right">'.$langs->trans("Amount").'</td>'; print '<td>'.$langs->trans("Line").'</td><td>'.$langs->trans("ThirdParty").'</td><td class="right">'.$langs->trans("Amount").'</td>';

View File

@ -30,7 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("banks","categories",'withdrawals','bills')); $langs->loadLangs(array("banks", "categories", 'withdrawals', 'bills'));
// Security check // Security check
if ($user->socid > 0) accessforbidden(); if ($user->socid > 0) accessforbidden();
@ -40,7 +40,7 @@ $prev_id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha'); $ref = GETPOST('ref', 'alpha');
// Load variable for pagination // Load variable for pagination
$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'alpha'); $sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOST('page', 'int'); $page = GETPOST('page', 'int');
@ -85,7 +85,7 @@ if ($prev_id > 0 || $ref)
print '</tr>'; print '</tr>';
*/ */
if($object->date_trans <> 0) if ($object->date_trans <> 0)
{ {
$muser = new User($db); $muser = new User($db);
$muser->fetch($object->user_trans); $muser->fetch($object->user_trans);
@ -97,7 +97,7 @@ if ($prev_id > 0 || $ref)
print $object->methodes_trans[$object->method_trans]; print $object->methodes_trans[$object->method_trans];
print '</td></tr>'; print '</td></tr>';
} }
if($object->date_credit <> 0) if ($object->date_credit <> 0)
{ {
print '<tr><td>'.$langs->trans('CreditDate').'</td><td>'; print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
print dol_print_date($object->date_credit, 'day'); print dol_print_date($object->date_credit, 'day');
@ -112,7 +112,7 @@ if ($prev_id > 0 || $ref)
print '<table class="border centpercent">'; print '<table class="border centpercent">';
$acc = new Account($db); $acc = new Account($db);
$result=$acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT); $result = $acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT);
print '<tr><td class="titlefield">'; print '<tr><td class="titlefield">';
print $langs->trans("BankToReceiveWithdraw"); print $langs->trans("BankToReceiveWithdraw");
@ -142,14 +142,14 @@ if ($prev_id > 0 || $ref)
/* /*
* Stats * Stats
*/ */
$ligne=new LignePrelevement($db, $user); $ligne = new LignePrelevement($db, $user);
$sql = "SELECT sum(pl.amount), pl.statut"; $sql = "SELECT sum(pl.amount), pl.statut";
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
$sql.= " WHERE pl.fk_prelevement_bons = ".$object->id; $sql .= " WHERE pl.fk_prelevement_bons = ".$object->id;
$sql.= " GROUP BY pl.statut"; $sql .= " GROUP BY pl.statut";
$resql=$db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
@ -174,7 +174,7 @@ if ($prev_id > 0 || $ref)
print price($row[0]); print price($row[0]);
print '</td><td class="right">'; print '</td><td class="right">';
if ($object->amount) print round($row[0]/$object->amount*100, 2)." %"; if ($object->amount) print round($row[0] / $object->amount * 100, 2)." %";
print '</td>'; print '</td>';
print "</tr>\n"; print "</tr>\n";
@ -188,7 +188,7 @@ if ($prev_id > 0 || $ref)
} }
else else
{ {
print $db->error() . ' ' . $sql; print $db->error().' '.$sql;
} }
} }

View File

@ -36,13 +36,13 @@ require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("other","compta","banks","bills","companies","product","trips","admin","accountancy")); $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin", "accountancy"));
$modecompta = (GETPOST('modecompta', 'alpha') ? GETPOST('modecompta', 'alpha') : $conf->global->ACCOUNTING_MODE); $modecompta = (GETPOST('modecompta', 'alpha') ? GETPOST('modecompta', 'alpha') : $conf->global->ACCOUNTING_MODE);
// Date range // Date range
$year=GETPOST("year", 'int'); $year = GETPOST("year", 'int');
$month=GETPOST("month", 'int'); $month = GETPOST("month", 'int');
if (empty($year)) if (empty($year))
{ {
$year_current = strftime("%Y", dol_now()); $year_current = strftime("%Y", dol_now());
@ -53,44 +53,44 @@ if (empty($year))
$month_current = strftime("%m", dol_now()); $month_current = strftime("%m", dol_now());
$year_start = $year; $year_start = $year;
} }
$date_start=dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear")); $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")); $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
// Quarter // Quarter
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"); $q = GETPOST("q", "int");
if (empty($q)) if (empty($q))
{ {
// We define date_start and date_end // We define date_start and date_end
$month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
$year_end=$year_start; $year_end = $year_start;
$month_end=$month_start; $month_end = $month_start;
if (! GETPOST("month")) // If month not forced if (!GETPOST("month")) // If month not forced
{ {
if (! GETPOST('year') && $month_start > $month_current) if (!GETPOST('year') && $month_start > $month_current)
{ {
$year_start--; $year_start--;
$year_end--; $year_end--;
} }
$month_end=$month_start-1; $month_end = $month_start - 1;
if ($month_end < 1) $month_end=12; if ($month_end < 1) $month_end = 12;
else $year_end++; else $year_end++;
} }
$date_start=dol_get_first_day($year_start, $month_start, false); $date_end=dol_get_last_day($year_end, $month_end, false); $date_start = dol_get_first_day($year_start, $month_start, false); $date_end = dol_get_last_day($year_end, $month_end, false);
} }
else 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 == 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 == 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 == 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 == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
} }
} }
// $date_start and $date_end are defined. We force $year_start and $nbofyear // $date_start and $date_end are defined. We force $year_start and $nbofyear
$tmps=dol_getdate($date_start); $tmps = dol_getdate($date_start);
$year_start = $tmps['year']; $year_start = $tmps['year'];
$tmpe=dol_getdate($date_end); $tmpe = dol_getdate($date_end);
$year_end = $tmpe['year']; $year_end = $tmpe['year'];
$tmp_date_end = dol_time_plus_duree($date_start, 1, 'y') - 1; $tmp_date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
@ -102,12 +102,12 @@ if (empty($min)) $min = 0;
// Define modetax (0 or 1) // Define modetax (0 or 1)
// 0=normal, 1=option vat for services is on debit, 2=option on payments for products // 0=normal, 1=option vat for services is on debit, 2=option on payments for products
$modetax = $conf->global->TAX_MODE; $modetax = $conf->global->TAX_MODE;
if (GETPOSTISSET("modetax")) $modetax=GETPOST("modetax", 'int'); if (GETPOSTISSET("modetax")) $modetax = GETPOST("modetax", 'int');
if (empty($modetax)) $modetax=0; if (empty($modetax)) $modetax = 0;
// Security check // Security check
$socid = GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
if ($user->socid) $socid=$user->socid; if ($user->socid) $socid = $user->socid;
$result = restrictedArea($user, 'tax', '', '', 'charges'); $result = restrictedArea($user, 'tax', '', '', 'charges');
@ -116,21 +116,21 @@ $result = restrictedArea($user, 'tax', '', '', 'charges');
* View * View
*/ */
$form=new Form($db); $form = new Form($db);
$company_static=new Societe($db); $company_static = new Societe($db);
$invoice_customer=new Facture($db); $invoice_customer = new Facture($db);
$invoice_supplier=new FactureFournisseur($db); $invoice_supplier = new FactureFournisseur($db);
$expensereport=new ExpenseReport($db); $expensereport = new ExpenseReport($db);
$product_static=new Product($db); $product_static = new Product($db);
$payment_static=new Paiement($db); $payment_static = new Paiement($db);
$paymentfourn_static=new PaiementFourn($db); $paymentfourn_static = new PaiementFourn($db);
$paymentexpensereport_static=new PaymentExpenseReport($db); $paymentexpensereport_static = new PaymentExpenseReport($db);
$morequerystring=''; $morequerystring = '';
$listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday'); $listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
foreach ($listofparams as $param) foreach ($listofparams as $param)
{ {
if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param); if (GETPOST($param) != '') $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
} }
llxHeader('', $langs->trans("TurnoverReport"), '', '', 0, 0, '', '', $morequerystring); llxHeader('', $langs->trans("TurnoverReport"), '', '', 0, 0, '', '', $morequerystring);
@ -139,103 +139,103 @@ llxHeader('', $langs->trans("TurnoverReport"), '', '', 0, 0, '', '', $morequerys
//print load_fiche_titre($langs->trans("VAT"),""); //print load_fiche_titre($langs->trans("VAT"),"");
//$fsearch.='<br>'; //$fsearch.='<br>';
$fsearch.=' <input type="hidden" name="year" value="'.$year.'">'; $fsearch .= ' <input type="hidden" name="year" value="'.$year.'">';
$fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">'; $fsearch .= ' <input type="hidden" name="modetax" value="'.$modetax.'">';
//$fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': '; //$fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': ';
//$fsearch.=' <input type="text" name="min" value="'.$min.'">'; //$fsearch.=' <input type="text" name="min" value="'.$min.'">';
// Show report header // Show report header
$name=$langs->trans("xxx"); $name = $langs->trans("xxx");
$calcmode=''; $calcmode = '';
if ($modetax == 0) $calcmode=$langs->trans('OptionVATDefault'); if ($modetax == 0) $calcmode = $langs->trans('OptionVATDefault');
if ($modetax == 1) $calcmode=$langs->trans('OptionVATDebitOption'); if ($modetax == 1) $calcmode = $langs->trans('OptionVATDebitOption');
if ($modetax == 2) $calcmode=$langs->trans('OptionPaymentForProductAndServices'); if ($modetax == 2) $calcmode = $langs->trans('OptionPaymentForProductAndServices');
$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')'; $calcmode .= '<br>('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')';
// Set period // 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); $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
$prevyear=$year_start; $prevquarter=$q; $prevyear = $year_start; $prevquarter = $q;
if ($prevquarter > 1) { if ($prevquarter > 1) {
$prevquarter--; $prevquarter--;
} else { } else {
$prevquarter=4; $prevyear--; $prevquarter = 4; $prevyear--;
} }
$nextyear=$year_start; $nextquarter=$q; $nextyear = $year_start; $nextquarter = $q;
if ($nextquarter < 4) { if ($nextquarter < 4) {
$nextquarter++; $nextquarter++;
} else { } else {
$nextquarter=1; $nextyear++; $nextquarter = 1; $nextyear++;
} }
$description.=$fsearch; $description .= $fsearch;
$builddate=dol_now(); $builddate = dol_now();
if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') $description.=$langs->trans("RulesVATDueProducts"); 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_PRODUCT == 'payment') $description .= $langs->trans("RulesVATInProducts");
if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') $description.='<br>'.$langs->trans("RulesVATDueServices"); if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') $description .= '<br>'.$langs->trans("RulesVATDueServices");
if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') $description.='<br>'.$langs->trans("RulesVATInServices"); if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') $description .= '<br>'.$langs->trans("RulesVATInServices");
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$description.='<br>'.$langs->trans("DepositsAreNotIncluded"); $description .= '<br>'.$langs->trans("DepositsAreNotIncluded");
} }
if (! empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description.='<br>'.$langs->trans("ThisIsAnEstimatedValue"); if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description .= '<br>'.$langs->trans("ThisIsAnEstimatedValue");
// Customers invoices // Customers invoices
$elementcust=$langs->trans("CustomersInvoices"); $elementcust = $langs->trans("CustomersInvoices");
$productcust=$langs->trans("ProductOrService"); $productcust = $langs->trans("ProductOrService");
$amountcust=$langs->trans("AmountHT"); $amountcust = $langs->trans("AmountHT");
// Suppliers invoices // Suppliers invoices
$elementsup=$langs->trans("SuppliersInvoices"); $elementsup = $langs->trans("SuppliersInvoices");
$productsup=$productcust; $productsup = $productcust;
$amountsup=$amountcust; $amountsup = $amountcust;
$namesup=$namecust; $namesup = $namecust;
// TODO Report from bookkeeping not yet available, so we switch on report on business events // TODO Report from bookkeeping not yet available, so we switch on report on business events
if ($modecompta=="BOOKKEEPING") $modecompta="CREANCES-DETTES"; if ($modecompta == "BOOKKEEPING") $modecompta = "CREANCES-DETTES";
if ($modecompta=="BOOKKEEPINGCOLLECTED") $modecompta="RECETTES-DEPENSES"; if ($modecompta == "BOOKKEEPINGCOLLECTED") $modecompta = "RECETTES-DEPENSES";
// Show report header // Show report header
if ($modecompta=="CREANCES-DETTES") { if ($modecompta == "CREANCES-DETTES") {
$name=$langs->trans("Turnover").', '.$langs->trans("ByVatRate"); $name = $langs->trans("Turnover").', '.$langs->trans("ByVatRate");
$calcmode=$langs->trans("CalcModeDebt"); $calcmode = $langs->trans("CalcModeDebt");
//$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')'; //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$description=$langs->trans("RulesCADue"); $description = $langs->trans("RulesCADue");
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$description.= $langs->trans("DepositsAreNotIncluded"); $description .= $langs->trans("DepositsAreNotIncluded");
} else { } else {
$description.= $langs->trans("DepositsAreIncluded"); $description .= $langs->trans("DepositsAreIncluded");
} }
$builddate=dol_now(); $builddate = dol_now();
} }
elseif ($modecompta=="RECETTES-DEPENSES") elseif ($modecompta == "RECETTES-DEPENSES")
{ {
$name=$langs->trans("TurnoverCollected").', '.$langs->trans("ByVatRate"); $name = $langs->trans("TurnoverCollected").', '.$langs->trans("ByVatRate");
$calcmode=$langs->trans("CalcModeEngagement"); $calcmode = $langs->trans("CalcModeEngagement");
//$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')'; //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
$description=$langs->trans("RulesCAIn"); $description = $langs->trans("RulesCAIn");
$description.= $langs->trans("DepositsAreIncluded"); $description .= $langs->trans("DepositsAreIncluded");
$builddate=dol_now(); $builddate = dol_now();
} }
elseif ($modecompta=="BOOKKEEPING") elseif ($modecompta == "BOOKKEEPING")
{ {
} }
elseif ($modecompta=="BOOKKEEPINGCOLLECTED") elseif ($modecompta == "BOOKKEEPINGCOLLECTED")
{ {
} }
$period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) $periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_start-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year_start+1).'&modecompta='.$modecompta.'">'.img_next().'</a>'; if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) $periodlink = '<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_start - 1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year_start + 1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
else $periodlink = ''; else $periodlink = '';
$description.=' <input type="hidden" name="modecompta" value="'.$modecompta.'">'; $description .= ' <input type="hidden" name="modecompta" value="'.$modecompta.'">';
report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode); report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
if (! empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING')
{ {
print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
} }
@ -243,62 +243,62 @@ if (! empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING')
if ($modecompta == 'CREANCES-DETTES') { if ($modecompta == 'CREANCES-DETTES') {
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td width="6%" class="right">' . $langs->trans("TurnoverbyVatrate") . '</td>'; print '<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans("TurnoverbyVatrate").'</td>';
print '<td class="left">' . $langs->trans("ProductOrService") . '</td>'; print '<td class="left">'.$langs->trans("ProductOrService").'</td>';
print '<td class="left">' . $langs->trans("Country") . '</td>'; print '<td class="left">'.$langs->trans("Country").'</td>';
$i=0; $i = 0;
while($i < 12) { while ($i < 12) {
$j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START); $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
if ($j > 12) $j -= 12; if ($j > 12) $j -= 12;
print '<td width="60" class="right">' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '</td>'; print '<td width="60" class="right">'.$langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT)).'</td>';
$i++; $i++;
} }
print '<td width="60" class="right"><b>' . $langs->trans("TotalHT") . '</b></td></tr>'; print '<td width="60" class="right"><b>'.$langs->trans("TotalHT").'</b></td></tr>';
$sql = "SELECT fd.tva_tx AS vatrate,"; $sql = "SELECT fd.tva_tx AS vatrate,";
$sql .= " fd.product_type AS product_type,"; $sql .= " fd.product_type AS product_type,";
$sql .= " cc.label AS country,"; $sql .= " cc.label AS country,";
for ($i = 1; $i <= 12; $i ++) { for ($i = 1; $i <= 12; $i++) {
$sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, 'fd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; $sql .= " SUM(".$db->ifsql('MONTH(f.datef)='.$i, 'fd.total_ht', '0').") AS month".str_pad($i, 2, '0', STR_PAD_LEFT).",";
} }
$sql .= " SUM(fd.total_ht) as total"; $sql .= " SUM(fd.total_ht) as total";
$sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe as soc ON soc.rowid = f.fk_soc"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as soc ON soc.rowid = f.fk_soc";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as cc ON cc.rowid = soc.fk_pays"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = soc.fk_pays";
$sql .= " WHERE f.datef >= '" . $db->idate($date_start) . "'"; $sql .= " WHERE f.datef >= '".$db->idate($date_start)."'";
$sql .= " AND f.datef <= '" . $db->idate($date_end) . "'"; $sql .= " AND f.datef <= '".$db->idate($date_end)."'";
$sql.= " AND f.fk_statut in (1,2)"; $sql .= " AND f.fk_statut in (1,2)";
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$sql.= " AND f.type IN (0,1,2,5)"; $sql .= " AND f.type IN (0,1,2,5)";
} else { } else {
$sql.= " AND f.type IN (0,1,2,3,5)"; $sql .= " AND f.type IN (0,1,2,3,5)";
} }
$sql .= " AND f.entity IN (" . getEntity('invoice', 0) . ")"; $sql .= " AND f.entity IN (".getEntity('invoice', 0).")";
$sql .= " GROUP BY fd.tva_tx,fd.product_type, cc.label "; $sql .= " GROUP BY fd.tva_tx,fd.product_type, cc.label ";
dol_syslog("htdocs/compta/tva/index.php sql=" . $sql, LOG_DEBUG); dol_syslog("htdocs/compta/tva/index.php sql=".$sql, LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$totalpermonth = array(); $totalpermonth = array();
while ( $obj = $db->fetch_object($resql)) { while ($obj = $db->fetch_object($resql)) {
print '<tr class="oddeven"><td class="right">' . vatrate($obj->vatrate) . '</td>'; print '<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).'</td>';
if ($obj->product_type == 0) { if ($obj->product_type == 0) {
print '<td class="left">'. $langs->trans("Product") . '</td>'; print '<td class="left">'.$langs->trans("Product").'</td>';
} else { } else {
print '<td class="left">'. $langs->trans("Service") . '</td>'; print '<td class="left">'.$langs->trans("Service").'</td>';
} }
print '<td>' .$obj->country . '</td>'; print '<td>'.$obj->country.'</td>';
for($i = 0; $i < 12; $i++) { for ($i = 0; $i < 12; $i++) {
$j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START); $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
if ($j > 12) $j -= 12; if ($j > 12) $j -= 12;
$monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT); $monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
print '<td class="right" width="6%">' . price($obj->$monthj) . '</td>'; print '<td class="right" width="6%">'.price($obj->$monthj).'</td>';
$totalpermonth[$j]=(empty($totalpermonth[$j])?0:$totalpermonth[$j])+$obj->$monthj; $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
} }
print '<td class="right" width="6%"><b>' . price($obj->total) . '</b></td>'; print '<td class="right" width="6%"><b>'.price($obj->total).'</b></td>';
$totalpermonth['total']=(empty($totalpermonth['total'])?0:$totalpermonth['total'])+$obj->total; $totalpermonth['total'] = (empty($totalpermonth['total']) ? 0 : $totalpermonth['total']) + $obj->total;
print '</tr>'; print '</tr>';
} }
$db->free($resql); $db->free($resql);
@ -307,77 +307,77 @@ if ($modecompta == 'CREANCES-DETTES') {
print '<tr class="liste_total"><td class="right"></td>'; print '<tr class="liste_total"><td class="right"></td>';
print '<td class="left"></td>'; print '<td class="left"></td>';
print '<td></td>'; print '<td></td>';
for($i = 0; $i < 12; $i++) { for ($i = 0; $i < 12; $i++) {
$j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START); $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
if ($j > 12) $j -= 12; if ($j > 12) $j -= 12;
$monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT); $monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
print '<td class="right" width="6%">' . price($totalpermonth[$j]) . '</td>'; print '<td class="right" width="6%">'.price($totalpermonth[$j]).'</td>';
} }
print '<td class="right" width="6%"><b>' . price($totalpermonth['total']) . '</b></td>'; print '<td class="right" width="6%"><b>'.price($totalpermonth['total']).'</b></td>';
print '</tr>'; print '</tr>';
} else { } else {
print $db->lasterror(); // Show last sql error print $db->lasterror(); // Show last sql error
} }
print '<tr class="liste_titre"><td width="6%" class="right">' . $langs->trans("PurchasebyVatrate") . '</td>'; print '<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans("PurchasebyVatrate").'</td>';
print '<td class="left">' . $langs->trans("ProductOrService") . '</td>'; print '<td class="left">'.$langs->trans("ProductOrService").'</td>';
print '<td class="left">' . $langs->trans("Country") . '</td>'; print '<td class="left">'.$langs->trans("Country").'</td>';
$i=0; $i = 0;
while($i < 12) while ($i < 12)
{ {
$j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START); $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
if ($j > 12) $j -= 12; if ($j > 12) $j -= 12;
print '<td width="60" class="right">' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '</td>'; print '<td width="60" class="right">'.$langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT)).'</td>';
$i++; $i++;
} }
print '<td width="60" class="right"><b>' . $langs->trans("TotalHT") . '</b></td></tr>'; print '<td width="60" class="right"><b>'.$langs->trans("TotalHT").'</b></td></tr>';
$sql2 = "SELECT ffd.tva_tx AS vatrate,"; $sql2 = "SELECT ffd.tva_tx AS vatrate,";
$sql2 .= " ffd.product_type AS product_type,"; $sql2 .= " ffd.product_type AS product_type,";
$sql2 .= " cc.label AS country,"; $sql2 .= " cc.label AS country,";
for($i = 1; $i <= 12; $i ++) { for ($i = 1; $i <= 12; $i++) {
$sql2 .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; $sql2 .= " SUM(".$db->ifsql('MONTH(ff.datef)='.$i, 'ffd.total_ht', '0').") AS month".str_pad($i, 2, '0', STR_PAD_LEFT).",";
} }
$sql2 .= " SUM(ffd.total_ht) as total"; $sql2 .= " SUM(ffd.total_ht) as total";
$sql2 .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as ffd"; $sql2 .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as ffd";
$sql2 .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn"; $sql2 .= " INNER JOIN ".MAIN_DB_PREFIX."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
$sql2 .= " INNER JOIN " . MAIN_DB_PREFIX . "societe as soc ON soc.rowid = ff.fk_soc"; $sql2 .= " INNER JOIN ".MAIN_DB_PREFIX."societe as soc ON soc.rowid = ff.fk_soc";
$sql2 .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as cc ON cc.rowid = soc.fk_pays"; $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = soc.fk_pays";
$sql2 .= " WHERE ff.datef >= '" . $db->idate($date_start) . "'"; $sql2 .= " WHERE ff.datef >= '".$db->idate($date_start)."'";
$sql2 .= " AND ff.datef <= '" . $db->idate($date_end) . "'"; $sql2 .= " AND ff.datef <= '".$db->idate($date_end)."'";
$sql.= " AND ff.fk_statut in (1,2)"; $sql .= " AND ff.fk_statut in (1,2)";
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$sql.= " AND ff.type IN (0,1,2,5)"; $sql .= " AND ff.type IN (0,1,2,5)";
} else { } else {
$sql.= " AND ff.type IN (0,1,2,3,5)"; $sql .= " AND ff.type IN (0,1,2,3,5)";
} }
$sql2 .= " AND ff.entity IN (" . getEntity("facture_fourn", 0) . ")"; $sql2 .= " AND ff.entity IN (".getEntity("facture_fourn", 0).")";
$sql2 .= " GROUP BY ffd.tva_tx, ffd.product_type, cc.label"; $sql2 .= " GROUP BY ffd.tva_tx, ffd.product_type, cc.label";
//print $sql2; //print $sql2;
dol_syslog("htdocs/compta/tva/index.php sql=" . $sql, LOG_DEBUG); dol_syslog("htdocs/compta/tva/index.php sql=".$sql, LOG_DEBUG);
$resql2 = $db->query($sql2); $resql2 = $db->query($sql2);
if ($resql2) { if ($resql2) {
$num = $db->num_rows($resql2); $num = $db->num_rows($resql2);
$totalpermonth = array(); $totalpermonth = array();
while ( $obj = $db->fetch_object($resql2)) { while ($obj = $db->fetch_object($resql2)) {
print '<tr class="oddeven"><td class="right">' . vatrate($obj->vatrate) . '</td>'; print '<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).'</td>';
if ($obj->product_type == 0) { if ($obj->product_type == 0) {
print '<td class="left">'. $langs->trans("Product") . '</td>'; print '<td class="left">'.$langs->trans("Product").'</td>';
} else { } else {
print '<td class="left">'. $langs->trans("Service") . '</td>'; print '<td class="left">'.$langs->trans("Service").'</td>';
} }
print '<td>' . $obj->country . '</td>'; print '<td>'.$obj->country.'</td>';
for($i = 0; $i < 12; $i++) { for ($i = 0; $i < 12; $i++) {
$j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START); $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
if ($j > 12) $j -= 12; if ($j > 12) $j -= 12;
$monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT); $monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
print '<td class="right" width="6%">' . price($obj->$monthj) . '</td>'; print '<td class="right" width="6%">'.price($obj->$monthj).'</td>';
$totalpermonth[$j]=(empty($totalpermonth[$j])?0:$totalpermonth[$j])+$obj->$monthj; $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
} }
print '<td class="right" width="6%"><b>' . price($obj->total) . '</b></td>'; print '<td class="right" width="6%"><b>'.price($obj->total).'</b></td>';
$totalpermonth['total']=(empty($totalpermonth['total'])?0:$totalpermonth['total'])+$obj->total; $totalpermonth['total'] = (empty($totalpermonth['total']) ? 0 : $totalpermonth['total']) + $obj->total;
print '</tr>'; print '</tr>';
} }
$db->free($resql2); $db->free($resql2);
@ -386,13 +386,13 @@ if ($modecompta == 'CREANCES-DETTES') {
print '<tr class="liste_total"><td class="right"></td>'; print '<tr class="liste_total"><td class="right"></td>';
print '<td class="left"></td>'; print '<td class="left"></td>';
print '<td></td>'; print '<td></td>';
for($i = 0; $i < 12; $i++) { for ($i = 0; $i < 12; $i++) {
$j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START); $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
if ($j > 12) $j -= 12; if ($j > 12) $j -= 12;
$monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT); $monthj = 'month'.str_pad($j, 2, '0', STR_PAD_LEFT);
print '<td class="right" width="6%">' . price($totalpermonth[$j]) . '</td>'; print '<td class="right" width="6%">'.price($totalpermonth[$j]).'</td>';
} }
print '<td class="right" width="6%"><b>' . price($totalpermonth['total']) . '</b></td>'; print '<td class="right" width="6%"><b>'.price($totalpermonth['total']).'</b></td>';
print '</tr>'; print '</tr>';
} else { } else {
print $db->lasterror(); // Show last sql error print $db->lasterror(); // Show last sql error
@ -403,7 +403,7 @@ if ($modecompta == 'CREANCES-DETTES') {
// "Calculation of part of each product for accountancy in this mode is not possible. When a partial payment (for example 5 euros) is done on an // "Calculation of part of each product for accountancy in this mode is not possible. When a partial payment (for example 5 euros) is done on an
// invoice with 2 product (product A for 10 euros and product B for 20 euros), what is part of paiment for product A and part of paiment for product B ? // invoice with 2 product (product A for 10 euros and product B for 20 euros), what is part of paiment for product A and part of paiment for product B ?
// Because there is no way to know this, this report is not relevant. // Because there is no way to know this, this report is not relevant.
print '<br>'.$langs->trans("TurnoverPerSaleTaxRateInCommitmentAccountingNotRelevant") . '<br>'; print '<br>'.$langs->trans("TurnoverPerSaleTaxRateInCommitmentAccountingNotRelevant").'<br>';
} }
// End of page // End of page

View File

@ -30,21 +30,21 @@
* \brief Page to invoice multiple supplier orders * \brief Page to invoice multiple supplier orders
*/ */
require '../../main.inc.php'; require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
if (! empty($conf->projet->enabled)) { if (!empty($conf->projet->enabled)) {
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
} }
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("orders", "companies", "deliveries")); $langs->loadLangs(array("orders", "companies", "deliveries"));
if (! $user->rights->fournisseur->facture->creer) if (!$user->rights->fournisseur->facture->creer)
accessforbidden(); accessforbidden();
$id = (GETPOST('id') ? GETPOST('id', 'int') : GETPOST("facid")); // For backward compatibility $id = (GETPOST('id') ? GETPOST('id', 'int') : GETPOST("facid")); // For backward compatibility
@ -53,16 +53,16 @@ $action = GETPOST('action', 'alpha');
$confirm = GETPOST('confirm', 'alpha'); $confirm = GETPOST('confirm', 'alpha');
$sref = GETPOST('sref'); $sref = GETPOST('sref');
$sref_client = GETPOST('sref_client'); $sref_client = GETPOST('sref_client');
$sall = trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml')); $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
$socid = GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
$selected = GETPOST('orders_to_invoice'); $selected = GETPOST('orders_to_invoice');
$sortfield = GETPOST("sortfield", 'alpha'); $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha');
$viewstatut = GETPOST('viewstatut'); $viewstatut = GETPOST('viewstatut');
if (! $sortfield) if (!$sortfield)
$sortfield = 'c.rowid'; $sortfield = 'c.rowid';
if (! $sortorder) if (!$sortorder)
$sortorder = 'DESC'; $sortorder = 'DESC';
$now = dol_now(); $now = dol_now();
@ -80,13 +80,13 @@ $extrafields->fetch_name_optionals_label($object->table_element);
if ($action == 'create') if ($action == 'create')
{ {
if (! GETPOST('createbill')) if (!GETPOST('createbill'))
{ {
$action = ''; $action = '';
} }
else else
{ {
if (! is_array($selected)) if (!is_array($selected))
{ {
//$error++; //$error++;
setEventMessages($langs->trans('Error_OrderNotChecked'), null, 'errors'); setEventMessages($langs->trans('Error_OrderNotChecked'), null, 'errors');
@ -99,7 +99,7 @@ if ($action == 'create')
} }
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager = new HookManager($db); $hookmanager = new HookManager($db);
$hookmanager->initHooks(array('orderstoinvoicesupplier')); $hookmanager->initHooks(array('orderstoinvoicesupplier'));
@ -108,10 +108,10 @@ $hookmanager->initHooks(array('orderstoinvoicesupplier'));
* Actions * Actions
*/ */
if (($action == 'create' || $action == 'add') && ! $error) { if (($action == 'create' || $action == 'add') && !$error) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
if (! empty($conf->projet->enabled)) if (!empty($conf->projet->enabled))
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("bills", "main", "products")); $langs->loadLangs(array("bills", "main", "products"));
@ -157,7 +157,7 @@ if (($action == 'create' || $action == 'add') && ! $error) {
if (empty($datefacture)) { if (empty($datefacture)) {
$datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y")); $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
} }
if (! $error) { if (!$error) {
$object->ref = GETPOST('ref', 'nohtml'); $object->ref = GETPOST('ref', 'nohtml');
$object->ref_supplier = GETPOST('ref_supplier', 'alpha'); $object->ref_supplier = GETPOST('ref_supplier', 'alpha');
$object->socid = GETPOST('socid', 'int'); $object->socid = GETPOST('socid', 'int');
@ -181,18 +181,18 @@ if (($action == 'create' || $action == 'add') && ! $error) {
if ($ret < 0) $error++; if ($ret < 0) $error++;
if ($_POST['origin'] && $_POST['originid']) { if ($_POST['origin'] && $_POST['originid']) {
$linked_orders_ids=array(); $linked_orders_ids = array();
foreach ($orders_id as $origin => $origin_id) { foreach ($orders_id as $origin => $origin_id) {
$origin_id = (! empty($origin_id) ? $origin_id : $orders_id[$ii]); $origin_id = (!empty($origin_id) ? $origin_id : $orders_id[$ii]);
$linked_orders_ids[]=$origin_id; $linked_orders_ids[] = $origin_id;
} }
$object->linked_objects = array(GETPOST('origin')=>$linked_orders_ids); $object->linked_objects = array(GETPOST('origin')=>$linked_orders_ids);
$id = $object->create($user); $id = $object->create($user);
if ($id > 0) { if ($id > 0) {
while ( $ii < $nn ) { while ($ii < $nn) {
$objectsrc = new CommandeFournisseur($db); $objectsrc = new CommandeFournisseur($db);
dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines"); dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
$result = $objectsrc->fetch($orders_id[$ii]); $result = $objectsrc->fetch($orders_id[$ii]);
if ($result > 0) { if ($result > 0) {
$lines = $objectsrc->lines; $lines = $objectsrc->lines;
@ -202,7 +202,7 @@ if (($action == 'create' || $action == 'add') && ! $error) {
} }
$fk_parent_line = 0; $fk_parent_line = 0;
$num = count($lines); $num = count($lines);
for($i = 0; $i < $num; $i ++) { for ($i = 0; $i < $num; $i++) {
$desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle); $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
$desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle); $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
@ -232,7 +232,7 @@ if (($action == 'create' || $action == 'add') && ! $error) {
$lineid = $result; $lineid = $result;
} else { } else {
$lineid = 0; $lineid = 0;
$error ++; $error++;
break; break;
} }
// Defined the new fk_parent_line // Defined the new fk_parent_line
@ -242,22 +242,22 @@ if (($action == 'create' || $action == 'add') && ! $error) {
} }
} else { } else {
$mesgs[] = $objectsrc->error; $mesgs[] = $objectsrc->error;
$error ++; $error++;
} }
$ii ++; $ii++;
} }
} else { } else {
$mesgs[] = $object->error; $mesgs[] = $object->error;
$error ++; $error++;
} }
} }
} }
// End of object creation, we show it // End of object creation, we show it
if ($id > 0 && ! $error) { if ($id > 0 && !$error) {
foreach($orders_id as $fk_supplier_order) { foreach ($orders_id as $fk_supplier_order) {
$supplier_order = new CommandeFournisseur($db); $supplier_order = new CommandeFournisseur($db);
if ($supplier_order->fetch($fk_supplier_order)>0 && $supplier_order->statut == 5) if ($supplier_order->fetch($fk_supplier_order) > 0 && $supplier_order->statut == 5)
{ {
if ($supplier_order->classifyBilled($user) < 0) if ($supplier_order->classifyBilled($user) < 0)
{ {
@ -265,7 +265,7 @@ if (($action == 'create' || $action == 'add') && ! $error) {
$action = 'create'; $action = 'create';
$_GET["origin"] = $_POST["origin"]; $_GET["origin"] = $_POST["origin"];
$_GET["originid"] = $_POST["originid"]; $_GET["originid"] = $_POST["originid"];
$mesgs[] = '<div class="error">' . $object->error . '</div>'; $mesgs[] = '<div class="error">'.$object->error.'</div>';
$error++; $error++;
break; break;
@ -273,9 +273,9 @@ if (($action == 'create' || $action == 'add') && ! $error) {
} }
} }
if(!$error) { if (!$error) {
$db->commit(); $db->commit();
header('Location: ' . DOL_URL_ROOT . '/fourn/facture/card.php?facid=' . $id); header('Location: '.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id);
exit(); exit();
} }
} else { } else {
@ -283,7 +283,7 @@ if (($action == 'create' || $action == 'add') && ! $error) {
$action = 'create'; $action = 'create';
$_GET["origin"] = $_POST["origin"]; $_GET["origin"] = $_POST["origin"];
$_GET["originid"] = $_POST["originid"]; $_GET["originid"] = $_POST["originid"];
$mesgs[] = '<div class="error">' . $object->error . '</div>'; $mesgs[] = '<div class="error">'.$object->error.'</div>';
} }
} }
} }
@ -308,7 +308,7 @@ if ($action == 'create' && !$error) {
$cond_reglement_id = $soc->cond_reglement_supplier_id; $cond_reglement_id = $soc->cond_reglement_supplier_id;
$mode_reglement_id = $soc->mode_reglement_supplier_id; $mode_reglement_id = $soc->mode_reglement_supplier_id;
} }
$dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? - 1 : ''; $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 : '';
$objectsrc = new CommandeFournisseur($db); $objectsrc = new CommandeFournisseur($db);
$listoforders = array(); $listoforders = array();
@ -322,50 +322,50 @@ if ($action == 'create' && !$error) {
if (empty($mode_reglement_id)) $mode_reglement_id = $objectsrc->mode_reglement_id; if (empty($mode_reglement_id)) $mode_reglement_id = $objectsrc->mode_reglement_id;
} }
print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="socid" value="' . $soc->id . '">' . "\n"; print '<input type="hidden" name="socid" value="'.$soc->id.'">'."\n";
print '<input name="ref" type="hidden" value="provisoire">'; print '<input name="ref" type="hidden" value="provisoire">';
print '<input name="ref_client" type="hidden" value="' . $ref_client . '">'; print '<input name="ref_client" type="hidden" value="'.$ref_client.'">';
print '<input name="ref_int" type="hidden" value="' . $ref_int . '">'; print '<input name="ref_int" type="hidden" value="'.$ref_int.'">';
print '<input type="hidden" name="origin" value="' . GETPOST('origin') . '">'; print '<input type="hidden" name="origin" value="'.GETPOST('origin').'">';
print '<input type="hidden" name="originid" value="' . GETPOST('originid') . '">'; print '<input type="hidden" name="originid" value="'.GETPOST('originid').'">';
print '<input type="hidden" name="socid" value="' . $soc->id . '">'; print '<input type="hidden" name="socid" value="'.$soc->id.'">';
print '<table class="border centpercent">'; print '<table class="border centpercent">';
// Ref // Ref
print '<tr><td class="fieldrequired">' . $langs->trans('Ref') . '</td><td colspan="2">' . $langs->trans('Draft') . '</td></tr>'; print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans('Draft').'</td></tr>';
// Ref supplier // Ref supplier
print '<tr><td class="fieldrequired">' . $langs->trans('RefSupplier') . '</td><td><input name="ref_supplier" value="' . dol_escape_htmltag(isset($_POST['ref_supplier']) ? GETPOST('ref_supplier', 'alpha', 2) : '') . '" type="text"></td>'; print '<tr><td class="fieldrequired">'.$langs->trans('RefSupplier').'</td><td><input name="ref_supplier" value="'.dol_escape_htmltag(isset($_POST['ref_supplier']) ? GETPOST('ref_supplier', 'alpha', 2) : '').'" type="text"></td>';
print '</tr>'; print '</tr>';
// Date invoice // Date invoice
print '<tr><td class="fieldrequired">' . $langs->trans('Date') . '</td><td colspan="2">'; print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td colspan="2">';
print $html->selectDate('', '', '', '', '', "add", 1, 1); print $html->selectDate('', '', '', '', '', "add", 1, 1);
print '</td></tr>'; print '</td></tr>';
// Payment term // Payment term
print '<tr><td class="nowrap">' . $langs->trans('PaymentConditionsShort') . '</td><td colspan="2">'; print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
$html->select_conditions_paiements(isset($_POST['cond_reglement_id']) ? $_POST['cond_reglement_id'] : $cond_reglement_id, 'cond_reglement_id'); $html->select_conditions_paiements(isset($_POST['cond_reglement_id']) ? $_POST['cond_reglement_id'] : $cond_reglement_id, 'cond_reglement_id');
print '</td></tr>'; print '</td></tr>';
// Payment mode // Payment mode
print '<tr><td>' . $langs->trans('PaymentMode') . '</td><td colspan="2">'; print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
$html->select_types_paiements(isset($_POST['mode_reglement_id']) ? $_POST['mode_reglement_id'] : $mode_reglement_id, 'mode_reglement_id'); $html->select_types_paiements(isset($_POST['mode_reglement_id']) ? $_POST['mode_reglement_id'] : $mode_reglement_id, 'mode_reglement_id');
print '</td></tr>'; print '</td></tr>';
// Project // Project
if (! empty($conf->projet->enabled)) { if (!empty($conf->projet->enabled)) {
$formproject = new FormProjets($db); $formproject = new FormProjets($db);
$langs->load('projects'); $langs->load('projects');
print '<tr><td>' . $langs->trans('Project') . '</td><td colspan="2">'; print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';
$formproject->select_projects($soc->id, $projectid, 'projectid'); $formproject->select_projects($soc->id, $projectid, 'projectid');
print '</td></tr>'; print '</td></tr>';
} }
// Other attributes // Other attributes
$parameters = array ( $parameters = array(
'objectsrc' => $objectsrc, 'objectsrc' => $objectsrc,
'idsrc' => $listoforders, 'idsrc' => $listoforders,
'colspan' => ' colspan="2"', 'colspan' => ' colspan="2"',
@ -376,12 +376,12 @@ if ($action == 'create' && !$error) {
if (empty($reshook)) if (empty($reshook))
{ {
$object=new FactureFournisseur($db); $object = new FactureFournisseur($db);
print $object->showOptionals($extrafields, 'edit'); print $object->showOptionals($extrafields, 'edit');
} }
// Modele PDF // Modele PDF
print '<tr><td>' . $langs->trans('Model') . '</td>'; print '<tr><td>'.$langs->trans('Model').'</td>';
print '<td>'; print '<td>';
$liste = ModelePDFSuppliersInvoices::liste_modeles($db); $liste = ModelePDFSuppliersInvoices::liste_modeles($db);
print $html->selectarray('model', $liste, $conf->global->INVOICE_SUPPLIER_ADDON_PDF); print $html->selectarray('model', $liste, $conf->global->INVOICE_SUPPLIER_ADDON_PDF);
@ -389,20 +389,20 @@ if ($action == 'create' && !$error) {
// Public note // Public note
print '<tr>'; print '<tr>';
print '<td class="tdtop">' . $langs->trans('NotePublic') . '</td>'; print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
print '<td colspan="2">'; print '<td colspan="2">';
print '<textarea name="note_public" wrap="soft" class="quatrevingtpercent" rows="' . ROWS_3 . '">'; print '<textarea name="note_public" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">';
print $langs->trans("Orders") . ": " . implode(', ', $listoforders); print $langs->trans("Orders").": ".implode(', ', $listoforders);
print '</textarea></td></tr>'; print '</textarea></td></tr>';
// Private note // Private note
if (empty($user->socid)) { if (empty($user->socid)) {
print '<tr>'; print '<tr>';
print '<td class="tdtop">' . $langs->trans('NotePrivate') . '</td>'; print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
print '<td colspan="2">'; print '<td colspan="2">';
print '<textarea name="note" wrap="soft" cols="70" rows="' . ROWS_3 . '">'; print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">';
print '</textarea></td></tr>'; print '</textarea></td></tr>';
} }
@ -410,13 +410,13 @@ if ($action == 'create' && !$error) {
print '</table>'; print '</table>';
while ($i < $n) { while ($i < $n) {
print '<input type="hidden" name="orders_to_invoice[]" value="' . $orders_id[$i] . '">'; print '<input type="hidden" name="orders_to_invoice[]" value="'.$orders_id[$i].'">';
$i++; $i++;
} }
// Button "Create Draft" // Button "Create Draft"
print '<br><div class="center"><input type="submit" class="button" name="bouton" value="' . $langs->trans('CreateDraft') . '" /></div>'; print '<br><div class="center"><input type="submit" class="button" name="bouton" value="'.$langs->trans('CreateDraft').'" /></div>';
print "</form>\n"; print "</form>\n";
print '</td></tr>'; print '</td></tr>';
@ -441,22 +441,22 @@ if (($action != 'create' && $action != 'add') && !$error) {
$sql = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_supplier,'; $sql = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_supplier,';
$sql .= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut'; $sql .= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s'; $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
$sql .= ', ' . MAIN_DB_PREFIX . 'commande_fournisseur as c'; $sql .= ', '.MAIN_DB_PREFIX.'commande_fournisseur as c';
if (! $user->rights->societe->client->voir && ! $socid) if (!$user->rights->societe->client->voir && !$socid)
$sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= ' WHERE c.entity = ' . $conf->entity; $sql .= ' WHERE c.entity = '.$conf->entity;
$sql .= ' AND c.fk_soc = s.rowid'; $sql .= ' AND c.fk_soc = s.rowid';
// Show orders we can bill // Show orders we can bill
if (empty($conf->global->SUPPLIER_ORDER_TO_INVOICE_STATUS)) if (empty($conf->global->SUPPLIER_ORDER_TO_INVOICE_STATUS))
{ {
$sql.= " AND c.fk_statut IN (".CommandeFournisseur::STATUS_RECEIVED_COMPLETELY.")"; // Must match filter in htdocs/fourn/card.php $sql .= " AND c.fk_statut IN (".CommandeFournisseur::STATUS_RECEIVED_COMPLETELY.")"; // Must match filter in htdocs/fourn/card.php
} }
else else
{ {
// CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.", ".CommandeFournisseur::STATUS_RECEIVED_COMPLETELY // CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.", ".CommandeFournisseur::STATUS_RECEIVED_COMPLETELY
$sql.= " AND c.fk_statut IN (".$db->escape($conf->global->SUPPLIER_ORDER_TO_INVOICE_STATUS).")"; $sql .= " AND c.fk_statut IN (".$db->escape($conf->global->SUPPLIER_ORDER_TO_INVOICE_STATUS).")";
} }
$sql .= " AND c.billed = 0"; $sql .= " AND c.billed = 0";
@ -466,33 +466,33 @@ if (($action != 'create' && $action != 'add') && !$error) {
//$sql .= " AND c.rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='invoice_supplier')"; //$sql .= " AND c.rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='invoice_supplier')";
if ($socid) if ($socid)
$sql .= ' AND s.rowid = ' . $socid; $sql .= ' AND s.rowid = '.$socid;
if (! $user->rights->societe->client->voir && ! $socid) if (!$user->rights->societe->client->voir && !$socid)
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($sref) { if ($sref) {
$sql .= natural_search("c.ref", $sref); $sql .= natural_search("c.ref", $sref);
} }
if ($sall) { if ($sall) {
$sql .= natural_search(array("c.ref","c.note"), $sall); $sql .= natural_search(array("c.ref", "c.note"), $sall);
} }
// Date filter // Date filter
//$sql.= dolSqlDateFilter("c.date_commande", GETPOST("date_startday", 'int'), GETPOST("date_startmonth", 'int'), GETPOST("date_startyear", 'int')); //$sql.= dolSqlDateFilter("c.date_commande", GETPOST("date_startday", 'int'), GETPOST("date_startmonth", 'int'), GETPOST("date_startyear", 'int'));
//$sql.= dolSqlDateFilter("c.date_livraison", $search_deliveryday, $search_deliverymonth, $search_deliveryyear); //$sql.= dolSqlDateFilter("c.date_livraison", $search_deliveryday, $search_deliverymonth, $search_deliveryyear);
if ($date_start) if ($date_start)
$sql .= " AND c.date_commande >= '" . $db->idate($date_start) . "'"; $sql .= " AND c.date_commande >= '".$db->idate($date_start)."'";
if ($date_end) if ($date_end)
$sql .= " AND c.date_commande <= '" . $db->idate($date_end) . "'"; $sql .= " AND c.date_commande <= '".$db->idate($date_end)."'";
if ($date_starty) if ($date_starty)
$sql .= " AND c.date_livraison >= '" . $db->idate($date_starty) . "'"; $sql .= " AND c.date_livraison >= '".$db->idate($date_starty)."'";
if ($date_endy) if ($date_endy)
$sql .= " AND c.date_livraison <= '" . $db->idate($date_endy) . "'"; $sql .= " AND c.date_livraison <= '".$db->idate($date_endy)."'";
if (! empty($sref_client)) { if (!empty($sref_client)) {
$sql .= natural_search('c.ref_supplier', $sref_client); $sql .= natural_search('c.ref_supplier', $sref_client);
} }
$sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder; $sql .= ' ORDER BY '.$sortfield.' '.$sortorder;
dol_syslog('fourn/commande/ordertoinvoice.php sql=' . $sql); dol_syslog('fourn/commande/ordertoinvoice.php sql='.$sql);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
@ -501,28 +501,28 @@ if (($action != 'create' && $action != 'add') && !$error) {
$soc->fetch($socid); $soc->fetch($socid);
} }
$title = $langs->trans('ListOfSupplierOrders'); $title = $langs->trans('ListOfSupplierOrders');
$title .= ' - ' . $langs->trans('StatusOrderReceivedAllShort'); $title .= ' - '.$langs->trans('StatusOrderReceivedAllShort');
$title .= ' - ' . $soc->getNomUrl(1, 'supplier'); $title .= ' - '.$soc->getNomUrl(1, 'supplier');
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
print load_fiche_titre($title); print load_fiche_titre($title);
$i = 0; $i = 0;
$period = $html->selectDate($date_start, 'date_start', 0, 0, 1, '', 1, 0) . ' - ' . $html->selectDate($date_end, 'date_end', 0, 0, 1, '', 1, 0); $period = $html->selectDate($date_start, 'date_start', 0, 0, 1, '', 1, 0).' - '.$html->selectDate($date_end, 'date_end', 0, 0, 1, '', 1, 0);
$periodely = $html->selectDate($date_starty, 'date_start_dely', 0, 0, 1, '', 1, 0) . ' - ' . $html->selectDate($date_endy, 'date_end_dely', 0, 0, 1, '', 1, 0); $periodely = $html->selectDate($date_starty, 'date_start_dely', 0, 0, 1, '', 1, 0).' - '.$html->selectDate($date_endy, 'date_end_dely', 0, 0, 1, '', 1, 0);
print '<form name="orders2invoice" method="GET" action="orderstoinvoice.php">'; print '<form name="orders2invoice" method="GET" action="orderstoinvoice.php">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="socid" value="' . $socid . '">'; print '<input type="hidden" name="socid" value="'.$socid.'">';
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print_liste_field_titre('Ref', 'orderstoinvoice.php', 'c.ref', '', '&amp;socid=' . $socid, '', $sortfield, $sortorder); print_liste_field_titre('Ref', 'orderstoinvoice.php', 'c.ref', '', '&amp;socid='.$socid, '', $sortfield, $sortorder);
print_liste_field_titre('RefSupplier', 'orderstoinvoice.php', 'c.ref_supplier', '', '&amp;socid=' . $socid, '', $sortfield, $sortorder); print_liste_field_titre('RefSupplier', 'orderstoinvoice.php', 'c.ref_supplier', '', '&amp;socid='.$socid, '', $sortfield, $sortorder);
print_liste_field_titre('OrderDate', 'orderstoinvoice.php', 'c.date_commande', '', '&amp;socid=' . $socid, '', $sortfield, $sortorder, 'center '); print_liste_field_titre('OrderDate', 'orderstoinvoice.php', 'c.date_commande', '', '&amp;socid='.$socid, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre('DeliveryDate', 'orderstoinvoice.php', 'c.date_livraison', '', '&amp;socid=' . $socid, '', $sortfield, $sortorder, 'center '); print_liste_field_titre('DeliveryDate', 'orderstoinvoice.php', 'c.date_livraison', '', '&amp;socid='.$socid, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre('Status', '', '', '', '', '', '', '', 'right '); print_liste_field_titre('Status', '', '', '', '', '', '', '', 'right ');
print_liste_field_titre('GenerateBill', '', '', '', '', '', '', '', 'center '); print_liste_field_titre('GenerateBill', '', '', '', '', '', '', '', 'center ');
print "</tr>\n"; print "</tr>\n";
@ -532,12 +532,12 @@ if (($action != 'create' && $action != 'add') && !$error) {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
// REF // REF
print '<input class="flat" size="10" type="text" name="sref" value="' . $sref . '">'; print '<input class="flat" size="10" type="text" name="sref" value="'.$sref.'">';
print '</td>'; print '</td>';
// print '<td class="liste_titre">'; // print '<td class="liste_titre">';
print '<td class="liste_titre left">'; print '<td class="liste_titre left">';
print '<input class="flat" type="text" size="10" name="sref_client" value="' . $sref_client . '">'; print '<input class="flat" type="text" size="10" name="sref_client" value="'.$sref_client.'">';
print '</td>'; print '</td>';
// DATE ORDER // DATE ORDER
@ -552,13 +552,13 @@ if (($action != 'create' && $action != 'add') && !$error) {
// SEARCH BUTTON // SEARCH BUTTON
print '<td class="right liste_titre">'; print '<td class="right liste_titre">';
print '<input type="image" class="liste_titre" name="button_search" src="' . img_picto($langs->trans("Search"), 'search.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("Search")) . '" title="' . dol_escape_htmltag($langs->trans("Search")) . '">'; print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '</td>'; print '</td>';
// ALL/NONE // ALL/NONE
print '<td class="liste_titre center">'; print '<td class="liste_titre center">';
if ($conf->use_javascript_ajax) if ($conf->use_javascript_ajax)
print '<a href="#" id="checkall">' . $langs->trans("All") . '</a> / <a href="#" id="checknone">' . $langs->trans("None") . '</a>'; print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a>';
print '</td>'; print '</td>';
print '</td></tr>'; print '</td></tr>';
@ -581,13 +581,13 @@ if (($action != 'create' && $action != 'add') && !$error) {
print '<td width="16" class="right nobordernopadding hideonsmartphone">'; print '<td width="16" class="right nobordernopadding hideonsmartphone">';
$filename = dol_sanitizeFileName($objp->ref); $filename = dol_sanitizeFileName($objp->ref);
$filedir = $conf->fournisseur->commande->dir_output . '/' . dol_sanitizeFileName($objp->ref); $filedir = $conf->fournisseur->commande->dir_output.'/'.dol_sanitizeFileName($objp->ref);
$urlsource = $_SERVER['PHP_SELF'] . '?id=' . $objp->rowid; $urlsource = $_SERVER['PHP_SELF'].'?id='.$objp->rowid;
print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir); print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
print '</td></tr></table>'; print '</td></tr></table>';
print '</td>'; print '</td>';
print '<td>' . $objp->ref_supplier . '</td>'; print '<td>'.$objp->ref_supplier.'</td>';
// Order date // Order date
print '<td class="center nowrap">'; print '<td class="center nowrap">';
@ -600,18 +600,18 @@ if (($action != 'create' && $action != 'add') && !$error) {
print '</td>'; print '</td>';
// Statut // Statut
print '<td class="right nowrap">' . $generic_commande->LibStatut($objp->fk_statut, 5) . '</td>'; print '<td class="right nowrap">'.$generic_commande->LibStatut($objp->fk_statut, 5).'</td>';
// Checkbox // Checkbox
print '<td class="center">'; print '<td class="center">';
print '<input class="flat checkformerge" type="checkbox" name="orders_to_invoice[]" value="' . $objp->rowid . '">'; print '<input class="flat checkformerge" type="checkbox" name="orders_to_invoice[]" value="'.$objp->rowid.'">';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
$total = $total + $objp->price; $total = $total + $objp->price;
$subtotal = $subtotal + $objp->price; $subtotal = $subtotal + $objp->price;
$i ++; $i++;
} }
print '</table>'; print '</table>';
@ -620,11 +620,11 @@ if (($action != 'create' && $action != 'add') && !$error) {
*/ */
print '<div class="center">'; print '<div class="center">';
print '<div class="right">'; print '<div class="right">';
print '<input type="hidden" name="socid" value="' . $socid . '">'; print '<input type="hidden" name="socid" value="'.$socid.'">';
print '<input type="hidden" name="action" value="create">'; print '<input type="hidden" name="action" value="create">';
print '<input type="hidden" name="origin" value="order_supplier"><br>'; print '<input type="hidden" name="origin" value="order_supplier"><br>';
// print '<a class="butAction" href="index.php">'.$langs->trans("GoBack").'</a>'; // print '<a class="butAction" href="index.php">'.$langs->trans("GoBack").'</a>';
print '<input type="submit" class="butAction" name="createbill" value="' . $langs->trans("GenerateBill") . '">'; print '<input type="submit" class="butAction" name="createbill" value="'.$langs->trans("GenerateBill").'">';
print '</div>'; print '</div>';
print '</div>'; print '</div>';

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
$langs->loadLangs(array("products","suppliers")); $langs->loadLangs(array("products", "suppliers"));
if (!$user->rights->produit->lire && !$user->rights->service->lire) accessforbidden(); if (!$user->rights->produit->lire && !$user->rights->service->lire) accessforbidden();
@ -42,7 +42,7 @@ $type = GETPOST('type');
$optioncss = GETPOST('optioncss', 'alpha'); $optioncss = GETPOST('optioncss', 'alpha');
// Load variable for pagination // Load variable for pagination
$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'alpha'); $sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOST('page', 'int'); $page = GETPOST('page', 'int');
@ -50,11 +50,11 @@ if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined,
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (! $sortfield) $sortfield="p.ref"; // Set here default search field if (!$sortfield) $sortfield = "p.ref"; // Set here default search field
if (! $sortorder) $sortorder="ASC"; if (!$sortorder) $sortorder = "ASC";
$fourn_id = GETPOST('fourn_id', 'intcomma'); $fourn_id = GETPOST('fourn_id', 'intcomma');
if ($user->socid) $fourn_id=$user->socid; if ($user->socid) $fourn_id = $user->socid;
$catid = GETPOST('catid', 'intcomma'); $catid = GETPOST('catid', 'intcomma');
@ -71,12 +71,12 @@ $extrafields = new ExtraFields($db);
* Put here all code to do according to value of "action" parameter * Put here all code to do according to value of "action" parameter
*/ */
if (GETPOST('cancel', 'alpha')) { $action='list'; $massaction=''; } if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
if (! GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; } if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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))
@ -85,17 +85,17 @@ if (empty($reshook))
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria // Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') ||GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
{ {
$sref = ''; $sref = '';
$sRefSupplier = ''; $sRefSupplier = '';
$snom = ''; $snom = '';
$search_field1=''; $search_field1 = '';
$search_field2=''; $search_field2 = '';
$search_date_creation=''; $search_date_creation = '';
$search_date_update=''; $search_date_update = '';
$toselect=''; $toselect = '';
$search_array_options=array(); $search_array_options = array();
} }
} }
@ -107,7 +107,7 @@ $form = new Form($db);
$productstatic = new Product($db); $productstatic = new Product($db);
$companystatic = new Societe($db); $companystatic = new Societe($db);
$title=$langs->trans("ProductsAndServices"); $title = $langs->trans("ProductsAndServices");
if ($fourn_id) if ($fourn_id)
{ {
@ -117,36 +117,36 @@ if ($fourn_id)
$arrayofmassactions = array( $arrayofmassactions = array(
'generate_doc'=>$langs->trans("ReGeneratePDF"), 'generate_doc'=>$langs->trans("ReGeneratePDF"),
'builddoc'=>$langs->trans("PDFMerge"), 'builddoc'=>$langs->trans("PDFMerge"),
'presend'=>$langs->trans("SendByMail"), 'presend'=>$langs->trans("SendByMail"),
); );
if ($user->rights->mymodule->supprimer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete"); if ($user->rights->mymodule->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array(); if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
$massactionbutton=$form->selectMassAction('', $arrayofmassactions); $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
$sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type, p.entity,"; $sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type, p.entity,";
$sql.= " ppf.fk_soc, ppf.ref_fourn, ppf.price as price, ppf.quantity as qty, ppf.unitprice,"; $sql .= " ppf.fk_soc, ppf.ref_fourn, ppf.price as price, ppf.quantity as qty, ppf.unitprice,";
$sql.= " s.rowid as socid, s.nom as name"; $sql .= " s.rowid as socid, s.nom as name";
// Add fields to SELECT from hooks // Add fields to SELECT from hooks
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action);
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
$sql .= $hookmanager->resPrint; $sql .= $hookmanager->resPrint;
$sql.= " FROM ".MAIN_DB_PREFIX."product as p"; $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
if ($catid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid"; if ($catid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON p.rowid = ppf.fk_product"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON p.rowid = ppf.fk_product";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ppf.fk_soc = s.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ppf.fk_soc = s.rowid";
$sql.= " WHERE p.entity IN (".getEntity('product').")"; $sql .= " WHERE p.entity IN (".getEntity('product').")";
if ($sRefSupplier) if ($sRefSupplier)
{ {
$sql .= natural_search('ppf.ref_fourn', $sRefSupplier); $sql .= natural_search('ppf.ref_fourn', $sRefSupplier);
} }
if (GETPOST('type')) if (GETPOST('type'))
{ {
$sql .= " AND p.fk_product_type = " . GETPOST('type', 'int'); $sql .= " AND p.fk_product_type = ".GETPOST('type', 'int');
} }
if ($sref) if ($sref)
{ {
@ -156,7 +156,7 @@ if ($snom)
{ {
$sql .= natural_search('p.label', $snom); $sql .= natural_search('p.label', $snom);
} }
if($catid) if ($catid)
{ {
$sql .= " AND cp.fk_categorie = ".$catid; $sql .= " AND cp.fk_categorie = ".$catid;
} }
@ -203,18 +203,18 @@ if ($resql)
exit; exit;
} }
if (! empty($supplier->id)) $texte = $langs->trans("ListOfSupplierProductForSupplier", $supplier->name); if (!empty($supplier->id)) $texte = $langs->trans("ListOfSupplierProductForSupplier", $supplier->name);
else $texte = $langs->trans("List"); else $texte = $langs->trans("List");
llxHeader("", "", $texte); llxHeader("", "", $texte);
$param="&tobuy=".$tobuy."&sref=".$sref."&snom=".$snom."&fourn_id=".$fourn_id.(isset($type)?"&amp;type=".$type:"").(empty($sRefSupplier)?"":"&amp;srefsupplier=".$sRefSupplier); $param = "&tobuy=".$tobuy."&sref=".$sref."&snom=".$snom."&fourn_id=".$fourn_id.(isset($type) ? "&amp;type=".$type : "").(empty($sRefSupplier) ? "" : "&amp;srefsupplier=".$sRefSupplier);
if ($optioncss != '') $param.='&optioncss='.$optioncss; if ($optioncss != '') $param .= '&optioncss='.$optioncss;
print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords); print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords);
if (! empty($catid)) if (!empty($catid))
{ {
print "<div id='ways'>"; print "<div id='ways'>";
$c = new Categorie($db); $c = new Categorie($db);
@ -232,10 +232,10 @@ if ($resql)
print '<input type="hidden" name="page" value="'.$page.'">'; print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="type" value="'.$type.'">'; print '<input type="hidden" name="type" value="'.$type.'">';
$topicmail="Information"; $topicmail = "Information";
$modelmail="product"; $modelmail = "product";
$objecttmp=new Product($db); $objecttmp = new Product($db);
$trackid='prod'.$object->id; $trackid = 'prod'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
print '<table class="liste centpercent">'; print '<table class="liste centpercent">';
@ -261,7 +261,7 @@ if ($resql)
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
print $hookmanager->resPrint; print $hookmanager->resPrint;
print '<td class="liste_titre maxwidthsearch">'; print '<td class="liste_titre maxwidthsearch">';
$searchpicto=$form->showFilterButtons(); $searchpicto = $form->showFilterButtons();
print $searchpicto; print $searchpicto;
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -292,10 +292,10 @@ if ($resql)
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'; print '<td>';
$productstatic->id=$objp->rowid; $productstatic->id = $objp->rowid;
$productstatic->ref=$objp->ref; $productstatic->ref = $objp->ref;
$productstatic->type=$objp->fk_product_type; $productstatic->type = $objp->fk_product_type;
$productstatic->entity=$objp->entity; $productstatic->entity = $objp->entity;
print $productstatic->getNomUrl(1, 'supplier'); print $productstatic->getNomUrl(1, 'supplier');
print '</td>'; print '</td>';
@ -303,8 +303,8 @@ if ($resql)
print '<td>'.$objp->label.'</td>'."\n"; print '<td>'.$objp->label.'</td>'."\n";
$companystatic->name=$objp->name; $companystatic->name = $objp->name;
$companystatic->id=$objp->socid; $companystatic->id = $objp->socid;
print '<td>'; print '<td>';
if ($companystatic->id > 0) print $companystatic->getNomUrl(1, 'supplier'); if ($companystatic->id > 0) print $companystatic->getNomUrl(1, 'supplier');
print '</td>'; print '</td>';

View File

@ -39,26 +39,26 @@ require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_expression.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_expression.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
if(!empty($conf->barcode->enabled)) dol_include_once('/core/class/html.formbarcode.class.php'); if (!empty($conf->barcode->enabled)) dol_include_once('/core/class/html.formbarcode.class.php');
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array('products', 'suppliers', 'bills', 'margins')); $langs->loadLangs(array('products', 'suppliers', 'bills', 'margins'));
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha'); $ref = GETPOST('ref', 'alpha');
$rowid=GETPOST('rowid', 'int'); $rowid = GETPOST('rowid', 'int');
$action=GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$cancel=GETPOST('cancel', 'alpha'); $cancel = GETPOST('cancel', 'alpha');
$contextpage=GETPOST('contextpage', 'aZ')?GETPOST('contextpage', 'aZ'):'pricesuppliercard'; $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'pricesuppliercard';
$socid=GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
$cost_price=GETPOST('cost_price', 'alpha'); $cost_price = GETPOST('cost_price', 'alpha');
$backtopage=GETPOST('backtopage', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha');
$error=0; $error = 0;
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
// If socid provided by ajax company selector // If socid provided by ajax company selector
if (! empty($_REQUEST['search_fourn_id'])) if (!empty($_REQUEST['search_fourn_id']))
{ {
$_GET['id_fourn'] = $_GET['search_fourn_id']; $_GET['id_fourn'] = $_GET['search_fourn_id'];
$_POST['id_fourn'] = $_POST['search_fourn_id']; $_POST['id_fourn'] = $_POST['search_fourn_id'];
@ -66,26 +66,26 @@ if (! empty($_REQUEST['search_fourn_id']))
} }
// Security check // Security check
$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
$fieldtype = (! empty($ref) ? 'ref' : 'rowid'); $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
if ($user->socid) $socid=$user->socid; if ($user->socid) $socid = $user->socid;
$result=restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
if (empty($user->rights->fournisseur->lire)) accessforbidden(); if (empty($user->rights->fournisseur->lire)) accessforbidden();
$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha'); $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha');
$page = (GETPOST("page", 'int')?GETPOST("page", 'int'):0); $page = (GETPOST("page", 'int') ?GETPOST("page", 'int') : 0);
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; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (! $sortfield) $sortfield="s.nom"; if (!$sortfield) $sortfield = "s.nom";
if (! $sortorder) $sortorder="ASC"; if (!$sortorder) $sortorder = "ASC";
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('pricesuppliercard','globalcard')); $hookmanager->initHooks(array('pricesuppliercard', 'globalcard'));
$object = new ProductFournisseur($db); $object = new ProductFournisseur($db);
if ($id > 0 || $ref) if ($id > 0 || $ref)
@ -96,21 +96,21 @@ if ($id > 0 || $ref)
$sortfield = GETPOST("sortfield", 'alpha'); $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha');
if (! $sortfield) $sortfield="s.nom"; if (!$sortfield) $sortfield = "s.nom";
if (! $sortorder) $sortorder="ASC"; if (!$sortorder) $sortorder = "ASC";
/* /*
* Actions * Actions
*/ */
if ($cancel) $action=''; if ($cancel) $action = '';
$usercanread = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->lire) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->lire)); $usercanread = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->lire) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->lire));
$usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer)); $usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer));
$parameters=array('socid'=>$socid, 'id_prod'=>$id); $parameters = array('socid'=>$socid, 'id_prod'=>$id);
$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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))
@ -119,13 +119,13 @@ if (empty($reshook))
{ {
if ($id) if ($id)
{ {
$result=$object->fetch($id); $result = $object->fetch($id);
$object->cost_price = price2num($cost_price); $object->cost_price = price2num($cost_price);
$result=$object->update($object->id, $user); $result = $object->update($object->id, $user);
if ($result > 0) if ($result > 0)
{ {
setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
$action=''; $action = '';
} }
else else
{ {
@ -140,11 +140,11 @@ if (empty($reshook))
if ($rowid) // id of product supplier price to remove if ($rowid) // id of product supplier price to remove
{ {
$action = ''; $action = '';
$result=$object->remove_product_fournisseur_price($rowid); $result = $object->remove_product_fournisseur_price($rowid);
if($result > 0){ if ($result > 0) {
$db->query("DELETE FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = $rowid"); $db->query("DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields WHERE fk_object = $rowid");
setEventMessages($langs->trans("PriceRemoved"), null, 'mesgs'); setEventMessages($langs->trans("PriceRemoved"), null, 'mesgs');
}else{ } else {
$error++; $error++;
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
@ -153,23 +153,23 @@ if (empty($reshook))
if ($action == 'save_price') if ($action == 'save_price')
{ {
$id_fourn=GETPOST("id_fourn"); $id_fourn = GETPOST("id_fourn");
if (empty($id_fourn)) $id_fourn=GETPOST("search_id_fourn"); if (empty($id_fourn)) $id_fourn = GETPOST("search_id_fourn");
$ref_fourn=GETPOST("ref_fourn"); $ref_fourn = GETPOST("ref_fourn");
if (empty($ref_fourn)) $ref_fourn=GETPOST("search_ref_fourn"); if (empty($ref_fourn)) $ref_fourn = GETPOST("search_ref_fourn");
$ref_fourn_old=GETPOST("ref_fourn_old"); $ref_fourn_old = GETPOST("ref_fourn_old");
if (empty($ref_fourn_old)) $ref_fourn_old = $ref_fourn; if (empty($ref_fourn_old)) $ref_fourn_old = $ref_fourn;
$quantity=price2num(GETPOST("qty", 'nohtml'), 'MS'); $quantity = price2num(GETPOST("qty", 'nohtml'), 'MS');
$remise_percent=price2num(GETPOST('remise_percent', 'alpha')); $remise_percent = price2num(GETPOST('remise_percent', 'alpha'));
$npr = preg_match('/\*/', $_POST['tva_tx']) ? 1 : 0 ; $npr = preg_match('/\*/', $_POST['tva_tx']) ? 1 : 0;
$tva_tx = str_replace('*', '', GETPOST('tva_tx', 'alpha')); $tva_tx = str_replace('*', '', GETPOST('tva_tx', 'alpha'));
$tva_tx = price2num($tva_tx); $tva_tx = price2num($tva_tx);
$price_expression = GETPOST('eid', 'int') ? GETPOST('eid', 'int') : ''; // Discard expression if not in expression mode $price_expression = GETPOST('eid', 'int') ? GETPOST('eid', 'int') : ''; // Discard expression if not in expression mode
$delivery_time_days = GETPOST('delivery_time_days', 'int') ? GETPOST('delivery_time_days', 'int') : ''; $delivery_time_days = GETPOST('delivery_time_days', 'int') ? GETPOST('delivery_time_days', 'int') : '';
$supplier_reputation = GETPOST('supplier_reputation'); $supplier_reputation = GETPOST('supplier_reputation');
$supplier_description = GETPOST('supplier_description', 'alpha'); $supplier_description = GETPOST('supplier_description', 'alpha');
$barcode=GETPOST('barcode', 'alpha'); $barcode = GETPOST('barcode', 'alpha');
$fk_barcode_type=GETPOST('fk_barcode_type', 'int'); $fk_barcode_type = GETPOST('fk_barcode_type', 'int');
if ($tva_tx == '') if ($tva_tx == '')
{ {
@ -177,7 +177,7 @@ if (empty($reshook))
$langs->load("errors"); $langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("VATRateForSupplierProduct")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("VATRateForSupplierProduct")), null, 'errors');
} }
if (! is_numeric($tva_tx)) if (!is_numeric($tva_tx))
{ {
$error++; $error++;
$langs->load("errors"); $langs->load("errors");
@ -232,13 +232,13 @@ if (empty($reshook))
} }
} }
if (! $error) if (!$error)
{ {
$db->begin(); $db->begin();
if (! $error) if (!$error)
{ {
$ret=$object->add_fournisseur($user, $id_fourn, $ref_fourn_old, $quantity); // This insert record with no value for price. Values are update later with update_buyprice $ret = $object->add_fournisseur($user, $id_fourn, $ref_fourn_old, $quantity); // This insert record with no value for price. Values are update later with update_buyprice
if ($ret == -3) if ($ret == -3)
{ {
$error++; $error++;
@ -255,37 +255,37 @@ if (empty($reshook))
} }
} }
if (! $error) if (!$error)
{ {
$supplier=new Fournisseur($db); $supplier = new Fournisseur($db);
$result=$supplier->fetch($id_fourn); $result = $supplier->fetch($id_fourn);
if (isset($_POST['ref_fourn_price_id'])) if (isset($_POST['ref_fourn_price_id']))
$object->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']); $object->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']);
$extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); $extralabels = $extrafields->fetch_name_optionals_label("product_fournisseur_price");
$extrafield_values = $extrafields->getOptionalsFromPost("product_fournisseur_price"); $extrafield_values = $extrafields->getOptionalsFromPost("product_fournisseur_price");
$sql = ""; $sql = "";
$resql = $db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = " . $object->product_fourn_price_id); $resql = $db->query("SELECT * FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields WHERE fk_object = ".$object->product_fourn_price_id);
// Insert a new extrafields row, if none exists // Insert a new extrafields row, if none exists
if ($db->num_rows($resql) != 1) { if ($db->num_rows($resql) != 1) {
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields (fk_object, "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields (fk_object, ";
foreach ($extrafield_values as $key => $value) { foreach ($extrafield_values as $key => $value) {
$sql .= str_replace('options_', '', $key) . ', '; $sql .= str_replace('options_', '', $key).', ';
} }
$sql = substr($sql, 0, strlen($sql)-2) . ") VALUES (" . $object->product_fourn_price_id . ", "; $sql = substr($sql, 0, strlen($sql) - 2).") VALUES (".$object->product_fourn_price_id.", ";
foreach ($extrafield_values as $key => $value) { foreach ($extrafield_values as $key => $value) {
$sql .= '"' . $value . '", '; $sql .= '"'.$value.'", ';
} }
$sql = substr($sql, 0, strlen($sql)-2) . ')'; $sql = substr($sql, 0, strlen($sql) - 2).')';
} }
// else update the existing one // else update the existing one
else { else {
$sql = "UPDATE " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields SET "; $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields SET ";
foreach ($extrafield_values as $key => $value) { foreach ($extrafield_values as $key => $value) {
$sql .= str_replace('options_', '', $key) . ' = "' . $value . '", '; $sql .= str_replace('options_', '', $key).' = "'.$value.'", ';
} }
$sql = substr($sql, 0, strlen($sql)-2) . ' WHERE fk_object = ' . $object->product_fourn_price_id; $sql = substr($sql, 0, strlen($sql) - 2).' WHERE fk_object = '.$object->product_fourn_price_id;
} }
// Execute the sql command from above // Execute the sql command from above
@ -321,10 +321,10 @@ if (empty($reshook))
setEventMessages($priceparser->translatedError(), null, 'errors'); setEventMessages($priceparser->translatedError(), null, 'errors');
} }
} }
if (! $error && ! empty($conf->dynamicprices->enabled)) if (!$error && !empty($conf->dynamicprices->enabled))
{ {
//Set the price expression for this supplier price //Set the price expression for this supplier price
$ret=$object->setSupplierPriceExpression($price_expression); $ret = $object->setSupplierPriceExpression($price_expression);
if ($ret < 0) if ($ret < 0)
{ {
$error++; $error++;
@ -334,10 +334,10 @@ if (empty($reshook))
} }
} }
if (! $error) if (!$error)
{ {
$db->commit(); $db->commit();
$action=''; $action = '';
} }
else else
{ {
@ -361,13 +361,13 @@ $helpurl = '';
$shortlabel = dol_trunc($object->label, 16); $shortlabel = dol_trunc($object->label, 16);
if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT))
{ {
$title = $langs->trans('Product')." ". $shortlabel ." - ".$langs->trans('BuyingPrices'); $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('BuyingPrices');
$helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos'; $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
} }
if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE))
{ {
$title = $langs->trans('Service')." ". $shortlabel ." - ".$langs->trans('BuyingPrices'); $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('BuyingPrices');
$helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios'; $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
} }
llxHeader('', $title, $helpurl); llxHeader('', $title, $helpurl);
@ -380,23 +380,23 @@ if ($id > 0 || $ref)
{ {
if ($action == 'ask_remove_pf') { if ($action == 'ask_remove_pf') {
$form = new Form($db); $form = new Form($db);
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $id . '&rowid=' . $rowid, $langs->trans('DeleteProductBuyPrice'), $langs->trans('ConfirmDeleteProductBuyPrice'), 'confirm_remove_pf', '', 0, 1); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&rowid='.$rowid, $langs->trans('DeleteProductBuyPrice'), $langs->trans('ConfirmDeleteProductBuyPrice'), 'confirm_remove_pf', '', 0, 1);
echo $formconfirm; echo $formconfirm;
} }
if ($action <> 'edit' && $action <> 're-edit') if ($action <> 'edit' && $action <> 're-edit')
{ {
$head=product_prepare_head($object); $head = product_prepare_head($object);
$titre=$langs->trans("CardProduct".$object->type); $titre = $langs->trans("CardProduct".$object->type);
$picto=($object->type== Product::TYPE_SERVICE?'service':'product'); $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
dol_fiche_head($head, 'suppliers', $titre, -1, $picto); dol_fiche_head($head, 'suppliers', $titre, -1, $picto);
$linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$object->next_prev_filter=" fk_product_type = ".$object->type; $object->next_prev_filter = " fk_product_type = ".$object->type;
$shownav = 1; $shownav = 1;
if ($user->socid && ! in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0;
dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
@ -419,9 +419,9 @@ if ($id > 0 || $ref)
// Cost price. Can be used for margin module for option "calculate margin on explicit cost price // Cost price. Can be used for margin module for option "calculate margin on explicit cost price
// Accountancy sell code // Accountancy sell code
print '<tr><td>'; print '<tr><td>';
$textdesc =$langs->trans("CostPriceDescription"); $textdesc = $langs->trans("CostPriceDescription");
$textdesc.="<br>".$langs->trans("CostPriceUsage"); $textdesc .= "<br>".$langs->trans("CostPriceUsage");
$text=$form->textwithpicto($langs->trans("CostPrice"), $textdesc, 1, 'help', ''); $text = $form->textwithpicto($langs->trans("CostPrice"), $textdesc, 1, 'help', '');
print $form->editfieldkey($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6'); print $form->editfieldkey($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6');
print '</td><td colspan="2">'; print '</td><td colspan="2">';
print $form->editfieldval($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6'); print $form->editfieldval($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6');
@ -436,7 +436,7 @@ if ($id > 0 || $ref)
// Form to add or update a price // Form to add or update a price
if (($action == 'add_price' || $action == 'update_price' ) && $usercancreate) if (($action == 'add_price' || $action == 'update_price') && $usercancreate)
{ {
$langs->load("suppliers"); $langs->load("suppliers");
@ -462,7 +462,7 @@ if ($id > 0 || $ref)
print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Supplier").'</td><td>'; print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Supplier").'</td><td>';
if ($rowid) if ($rowid)
{ {
$supplier=new Fournisseur($db); $supplier = new Fournisseur($db);
$supplier->fetch($socid); $supplier->fetch($socid);
print $supplier->getNomUrl(1); print $supplier->getNomUrl(1);
print '<input type="hidden" name="id_fourn" value="'.$socid.'">'; print '<input type="hidden" name="id_fourn" value="'.$socid.'">';
@ -472,12 +472,12 @@ if ($id > 0 || $ref)
} }
else else
{ {
$events=array(); $events = array();
$events[]=array('method' => 'getVatRates', 'url' => dol_buildpath('/core/ajax/vatrates.php', 1), 'htmlname' => 'tva_tx', 'params' => array()); $events[] = array('method' => 'getVatRates', 'url' => dol_buildpath('/core/ajax/vatrates.php', 1), 'htmlname' => 'tva_tx', 'params' => array());
print $form->select_company(GETPOST("id_fourn", 'alpha'), 'id_fourn', 'fournisseur=1', 'SelectThirdParty', 0, 0, $events); print $form->select_company(GETPOST("id_fourn", 'alpha'), 'id_fourn', 'fournisseur=1', 'SelectThirdParty', 0, 0, $events);
$parameters=array('filtre'=>"fournisseur=1",'html_name'=>'id_fourn','selected'=>GETPOST("id_fourn"),'showempty'=>1,'prod_id'=>$object->id); $parameters = array('filtre'=>"fournisseur=1", 'html_name'=>'id_fourn', 'selected'=>GETPOST("id_fourn"), 'showempty'=>1, 'prod_id'=>$object->id);
$reshook=$hookmanager->executeHooks('formCreateThirdpartyOptions', $parameters, $object, $action); $reshook = $hookmanager->executeHooks('formCreateThirdpartyOptions', $parameters, $object, $action);
if (empty($reshook)) if (empty($reshook))
{ {
if (empty($form->result)) if (empty($form->result))
@ -497,13 +497,13 @@ if ($id > 0 || $ref)
} }
else else
{ {
print '<input class="flat" name="ref_fourn" size="12" value="'.(GETPOST("ref_fourn")?GETPOST("ref_fourn"):'').'">'; print '<input class="flat" name="ref_fourn" size="12" value="'.(GETPOST("ref_fourn") ?GETPOST("ref_fourn") : '').'">';
} }
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Availability // Availability
if (! empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY))
{ {
$langs->load("propal"); $langs->load("propal");
print '<tr><td>'.$langs->trans("Availability").'</td><td>'; print '<tr><td>'.$langs->trans("Availability").'</td><td>';
@ -529,46 +529,46 @@ if ($id > 0 || $ref)
if ($conf->global->PRODUCT_USE_UNITS) { if ($conf->global->PRODUCT_USE_UNITS) {
$unit = $object->getLabelOfUnit(); $unit = $object->getLabelOfUnit();
if ($unit !== '') { if ($unit !== '') {
print '&nbsp;&nbsp;' . $langs->trans($unit); print '&nbsp;&nbsp;'.$langs->trans($unit);
} }
} }
print '</td></tr>'; print '</td></tr>';
// Vat rate // Vat rate
$default_vat=''; $default_vat = '';
// We don't have supplier, so we try to guess. // We don't have supplier, so we try to guess.
// For this we build a fictive supplier with same properties than user but using vat) // For this we build a fictive supplier with same properties than user but using vat)
$mysoc2 = clone $mysoc; $mysoc2 = clone $mysoc;
$mysoc2->name='Fictive seller with same country'; $mysoc2->name = 'Fictive seller with same country';
$mysoc2->tva_assuj=1; $mysoc2->tva_assuj = 1;
$default_vat=get_default_tva($mysoc2, $mysoc, $object->id, 0); $default_vat = get_default_tva($mysoc2, $mysoc, $object->id, 0);
$default_npr=get_default_npr($mysoc2, $mysoc, $object->id, 0); $default_npr = get_default_npr($mysoc2, $mysoc, $object->id, 0);
if (empty($default_vat)) $default_npr=$default_vat; if (empty($default_vat)) $default_npr = $default_vat;
print '<tr><td class="fieldrequired">'.$langs->trans("VATRateForSupplierProduct").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("VATRateForSupplierProduct").'</td>';
print '<td>'; print '<td>';
//print $form->load_tva('tva_tx',$object->tva_tx,$supplier,$mysoc); // Do not use list here as it may be any vat rates for any country //print $form->load_tva('tva_tx',$object->tva_tx,$supplier,$mysoc); // Do not use list here as it may be any vat rates for any country
if (! empty($rowid)) // If we have a supplier, it is an update, we must show the vat of current supplier price if (!empty($rowid)) // If we have a supplier, it is an update, we must show the vat of current supplier price
{ {
$tmpproductsupplier=new ProductFournisseur($db); $tmpproductsupplier = new ProductFournisseur($db);
$tmpproductsupplier->fetch_product_fournisseur_price($rowid, 1); $tmpproductsupplier->fetch_product_fournisseur_price($rowid, 1);
$default_vat=$tmpproductsupplier->fourn_tva_tx; $default_vat = $tmpproductsupplier->fourn_tva_tx;
$default_npr=$tmpproductsupplier->fourn_tva_npr; $default_npr = $tmpproductsupplier->fourn_tva_npr;
} }
else else
{ {
if (empty($default_vat)) if (empty($default_vat))
{ {
$default_vat=$object->tva_tx; $default_vat = $object->tva_tx;
} }
} }
$vattosuggest=(GETPOST("tva_tx")?vatrate(GETPOST("tva_tx")):($default_vat!=''?vatrate($default_vat):'')); $vattosuggest = (GETPOST("tva_tx") ?vatrate(GETPOST("tva_tx")) : ($default_vat != '' ?vatrate($default_vat) : ''));
$vattosuggest=preg_replace('/\s*\(.*\)$/', '', $vattosuggest); $vattosuggest = preg_replace('/\s*\(.*\)$/', '', $vattosuggest);
print '<input type="text" class="flat" size="5" name="tva_tx" value="'.$vattosuggest.'">'; print '<input type="text" class="flat" size="5" name="tva_tx" value="'.$vattosuggest.'">';
print '</td></tr>'; print '</td></tr>';
if (! empty($conf->dynamicprices->enabled)) //Only show price mode and expression selector if module is enabled if (!empty($conf->dynamicprices->enabled)) //Only show price mode and expression selector if module is enabled
{ {
// Price mode selector // Price mode selector
print '<tr><td class="fieldrequired">'.$langs->trans("PriceMode").'</td><td>'; print '<tr><td class="fieldrequired">'.$langs->trans("PriceMode").'</td><td>';
@ -606,28 +606,28 @@ if ($id > 0 || $ref)
// Currency // Currency
print '<tr><td class="fieldrequired">'.$langs->trans("Currency").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("Currency").'</td>';
print '<td>'; print '<td>';
$currencycodetouse = GETPOST('multicurrency_code')?GETPOST('multicurrency_code'):(isset($object->fourn_multicurrency_code)?$object->fourn_multicurrency_code:''); $currencycodetouse = GETPOST('multicurrency_code') ?GETPOST('multicurrency_code') : (isset($object->fourn_multicurrency_code) ? $object->fourn_multicurrency_code : '');
if (empty($currencycodetouse) && $object->fourn_multicurrency_tx == 1) $currencycodetouse=$conf->currency; if (empty($currencycodetouse) && $object->fourn_multicurrency_tx == 1) $currencycodetouse = $conf->currency;
print $form->selectMultiCurrency($currencycodetouse, "multicurrency_code", 1); print $form->selectMultiCurrency($currencycodetouse, "multicurrency_code", 1);
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Currency tx // Currency tx
print '<tr><td class="fieldrequired">'.$langs->trans("CurrencyRate").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("CurrencyRate").'</td>';
print '<td><input class="flat" name="multicurrency_tx" size="4" value="'.vatrate(GETPOST('multicurrency_tx')?GETPOST('multicurrency_tx'):(isset($object->fourn_multicurrency_tx)?$object->fourn_multicurrency_tx:'')).'">'; print '<td><input class="flat" name="multicurrency_tx" size="4" value="'.vatrate(GETPOST('multicurrency_tx') ?GETPOST('multicurrency_tx') : (isset($object->fourn_multicurrency_tx) ? $object->fourn_multicurrency_tx : '')).'">';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Currency price qty min // Currency price qty min
print '<tr><td class="fieldrequired">'.$langs->trans("PriceQtyMinCurrency").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("PriceQtyMinCurrency").'</td>';
$pricesupplierincurrencytouse=(GETPOST('multicurrency_price')?GETPOST('multicurrency_price'):(isset($object->fourn_multicurrency_price)?$object->fourn_multicurrency_price:'')); $pricesupplierincurrencytouse = (GETPOST('multicurrency_price') ?GETPOST('multicurrency_price') : (isset($object->fourn_multicurrency_price) ? $object->fourn_multicurrency_price : ''));
print '<td><input class="flat" name="multicurrency_price" size="8" value="'.price($pricesupplierincurrencytouse).'">'; print '<td><input class="flat" name="multicurrency_price" size="8" value="'.price($pricesupplierincurrencytouse).'">';
print '&nbsp;'; print '&nbsp;';
print $form->selectPriceBaseType((GETPOST('multicurrency_price_base_type')?GETPOST('multicurrency_price_base_type'):'HT'), "multicurrency_price_base_type"); // We keep 'HT' here, multicurrency_price_base_type is not yet supported for supplier prices print $form->selectPriceBaseType((GETPOST('multicurrency_price_base_type') ?GETPOST('multicurrency_price_base_type') : 'HT'), "multicurrency_price_base_type"); // We keep 'HT' here, multicurrency_price_base_type is not yet supported for supplier prices
print '</td></tr>'; print '</td></tr>';
// Price qty min // Price qty min
print '<tr><td class="fieldrequired">' . $langs->trans("PriceQtyMin") . '</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("PriceQtyMin").'</td>';
print '<td><input class="flat" name="disabled_price" size="8" value="">'; print '<td><input class="flat" name="disabled_price" size="8" value="">';
print '<input type="hidden" name="price" value="">'; print '<input type="hidden" name="price" value="">';
print '<input type="hidden" name="price_base_type" value="">'; print '<input type="hidden" name="price_base_type" value="">';
@ -690,17 +690,17 @@ if ($id > 0 || $ref)
SCRIPT; SCRIPT;
} else { } else {
// Price qty min // Price qty min
print '<tr><td class="fieldrequired">' . $langs->trans("PriceQtyMin") . '</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("PriceQtyMin").'</td>';
print '<td><input class="flat" name="price" size="8" value="' . (GETPOST('price') ? price(GETPOST('price')) : (isset($object->fourn_price) ? price($object->fourn_price) : '')) . '">'; print '<td><input class="flat" name="price" size="8" value="'.(GETPOST('price') ? price(GETPOST('price')) : (isset($object->fourn_price) ? price($object->fourn_price) : '')).'">';
print '&nbsp;'; print '&nbsp;';
print $form->selectPriceBaseType((GETPOST('price_base_type') ? GETPOST('price_base_type') : 'HT'), "price_base_type"); // We keep 'HT' here, price_base_type is not yet supported for supplier prices print $form->selectPriceBaseType((GETPOST('price_base_type') ? GETPOST('price_base_type') : 'HT'), "price_base_type"); // We keep 'HT' here, price_base_type is not yet supported for supplier prices
print '</td></tr>'; print '</td></tr>';
} }
// Discount qty min // Discount qty min
print '<tr><td>'.$langs->trans("DiscountQtyMin").'</td>'; print '<tr><td>'.$langs->trans("DiscountQtyMin").'</td>';
print '<td><input class="flat" name="remise_percent" size="4" value="'.(GETPOST('remise_percent')?vatrate(GETPOST('remise_percent')):(isset($object->fourn_remise_percent)?vatrate($object->fourn_remise_percent):'')).'"> %'; print '<td><input class="flat" name="remise_percent" size="4" value="'.(GETPOST('remise_percent') ?vatrate(GETPOST('remise_percent')) : (isset($object->fourn_remise_percent) ?vatrate($object->fourn_remise_percent) : '')).'"> %';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -712,22 +712,22 @@ SCRIPT;
// Reputation // Reputation
print '<tr><td>'.$langs->trans("SupplierReputation").'</td><td>'; print '<tr><td>'.$langs->trans("SupplierReputation").'</td><td>';
echo $form->selectarray('supplier_reputation', $object->reputations, $supplier_reputation?$supplier_reputation:$object->supplier_reputation); echo $form->selectarray('supplier_reputation', $object->reputations, $supplier_reputation ? $supplier_reputation : $object->supplier_reputation);
print '</td></tr>'; print '</td></tr>';
// Barcode // Barcode
if (! empty($conf->barcode->enabled)) if (!empty($conf->barcode->enabled))
{ {
// Option to define a transport cost on supplier price // Option to define a transport cost on supplier price
print '<tr>'; print '<tr>';
print '<td>' . $langs->trans('BarcodeValue') . '</td>'; print '<td>'.$langs->trans('BarcodeValue').'</td>';
print '<td><input class="flat" name="barcode" value="'.($rowid ? $object->fourn_barcode : '').'"></td>'; print '<td><input class="flat" name="barcode" value="'.($rowid ? $object->fourn_barcode : '').'"></td>';
print '</tr>'; print '</tr>';
$formbarcode = new FormBarCode($db); $formbarcode = new FormBarCode($db);
// Barcode type // Barcode type
print '<tr>'; print '<tr>';
print '<td>' . $langs->trans('BarcodeType') . '</td>'; print '<td>'.$langs->trans('BarcodeType').'</td>';
print '<td>'; print '<td>';
print $formbarcode->selectBarcodeType(($rowid ? $object->fourn_fk_barcode_type : $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE), 'fk_barcode_type', 1); print $formbarcode->selectBarcodeType(($rowid ? $object->fourn_fk_barcode_type : $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE), 'fk_barcode_type', 1);
print '</td>'; print '</td>';
@ -737,18 +737,18 @@ SCRIPT;
// Option to define a transport cost on supplier price // Option to define a transport cost on supplier price
if ($conf->global->PRODUCT_CHARGES) if ($conf->global->PRODUCT_CHARGES)
{ {
if (! empty($conf->margin->enabled)) if (!empty($conf->margin->enabled))
{ {
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans("Charges").'</td>'; print '<td>'.$langs->trans("Charges").'</td>';
print '<td><input class="flat" name="charges" size="8" value="'.(GETPOST('charges')?price(GETPOST('charges')):(isset($object->fourn_charges)?price($object->fourn_charges):'')).'">'; print '<td><input class="flat" name="charges" size="8" value="'.(GETPOST('charges') ?price(GETPOST('charges')) : (isset($object->fourn_charges) ?price($object->fourn_charges) : '')).'">';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
} }
} }
// Product description of the supplier // Product description of the supplier
if (! empty($conf->global->PRODUIT_FOURN_TEXTS)) if (!empty($conf->global->PRODUIT_FOURN_TEXTS))
{ {
//WYSIWYG Editor //WYSIWYG Editor
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
@ -765,21 +765,21 @@ SCRIPT;
} }
$extrafields->fetch_name_optionals_label("product_fournisseur_price"); $extrafields->fetch_name_optionals_label("product_fournisseur_price");
$extralabels=$extrafields->attributes["product_fournisseur_price"]['label']; $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
// Extrafields // Extrafields
$resql = $db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = " . $rowid); $resql = $db->query("SELECT * FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields WHERE fk_object = ".$rowid);
if (!empty($extralabels)) { if (!empty($extralabels)) {
if ($db->num_rows($resql) != 1) { if ($db->num_rows($resql) != 1) {
foreach ($extralabels as $key => $value) { foreach ($extralabels as $key => $value) {
if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) { if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) {
print '<tr><td' . ($extrafields->attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '') . '>' . $langs->trans($value) . '</td><td>' . $extrafields->showInputField($key, '', '', '', '', '', 0, 'product_fournisseur_price') . '</td></tr>'; print '<tr><td'.($extrafields->attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '').'>'.$langs->trans($value).'</td><td>'.$extrafields->showInputField($key, '', '', '', '', '', 0, 'product_fournisseur_price').'</td></tr>';
} }
} }
} else { } else {
$resql = $db->fetch_object($resql); $resql = $db->fetch_object($resql);
foreach ($extralabels as $key => $value) { foreach ($extralabels as $key => $value) {
if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) { if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) {
print '<tr><td' . ($extrafields->attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '') . '>' . $langs->trans($value) . '</td><td>' . $extrafields->showInputField($key, $resql->{$key}, '', '', '', '', 0, 'product_fournisseur_price') . '</td></tr>'; print '<tr><td'.($extrafields->attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '').'>'.$langs->trans($value).'</td><td>'.$extrafields->showInputField($key, $resql->{$key}, '', '', '', '', 0, 'product_fournisseur_price').'</td></tr>';
} }
} }
} }
@ -787,8 +787,8 @@ SCRIPT;
if (is_object($hookmanager)) if (is_object($hookmanager))
{ {
$parameters=array('id_fourn'=>$id_fourn,'prod_id'=>$object->id); $parameters = array('id_fourn'=>$id_fourn, 'prod_id'=>$object->id);
$reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
print $hookmanager->resPrint; print $hookmanager->resPrint;
} }
@ -811,8 +811,8 @@ SCRIPT;
if ($action != 'add_price' && $action != 'update_price') if ($action != 'add_price' && $action != 'update_price')
{ {
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if (empty($reshook)) if (empty($reshook))
{ {
if ($usercancreate) if ($usercancreate)
@ -828,10 +828,10 @@ SCRIPT;
if ($user->rights->fournisseur->lire) // Duplicate ? this check is already in the head of this file if ($user->rights->fournisseur->lire) // Duplicate ? this check is already in the head of this file
{ {
$param=''; $param = '';
if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
$param.='&ref='.urlencode($object->ref); $param .= '&ref='.urlencode($object->ref);
$product_fourn = new ProductFournisseur($db); $product_fourn = new ProductFournisseur($db);
$product_fourn_list = $product_fourn->list_product_fournisseur_price($object->id, $sortfield, $sortorder, $limit, $offset); $product_fourn_list = $product_fourn->list_product_fournisseur_price($object->id, $sortfield, $sortorder, $limit, $offset);
@ -846,7 +846,7 @@ SCRIPT;
print '<div class="div-table-responsive">'; print '<div class="div-table-responsive">';
print '<table class="liste centpercent">'; print '<table class="liste centpercent">';
$param="&id=".$object->id; $param = "&id=".$object->id;
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print_liste_field_titre("AppliedPricesFrom", $_SERVER["PHP_SELF"], "pfp.datec", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("AppliedPricesFrom", $_SERVER["PHP_SELF"], "pfp.datec", "", $param, "", $sortfield, $sortorder);
@ -875,11 +875,11 @@ SCRIPT;
// fetch optionals attributes and labels // fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label("product_fournisseur_price"); $extrafields->fetch_name_optionals_label("product_fournisseur_price");
$extralabels=$extrafields->attributes["product_fournisseur_price"]['label']; $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
if (!empty($extralabels)) { if (!empty($extralabels)) {
foreach ($extralabels as $key => $value) { foreach ($extralabels as $key => $value) {
// Show field if not hidden // Show field if not hidden
if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {
print_liste_field_titre($value, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); print_liste_field_titre($value, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
} }
} }
@ -887,20 +887,20 @@ SCRIPT;
if (is_object($hookmanager)) if (is_object($hookmanager))
{ {
$parameters=array('id_fourn'=>$id_fourn, 'prod_id'=>$object->id); $parameters = array('id_fourn'=>$id_fourn, 'prod_id'=>$object->id);
$reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action);
} }
print_liste_field_titre(''); print_liste_field_titre('');
print "</tr>\n"; print "</tr>\n";
if (is_array($product_fourn_list)) if (is_array($product_fourn_list))
{ {
foreach($product_fourn_list as $productfourn) foreach ($product_fourn_list as $productfourn)
{ {
print '<tr class="oddeven">'; print '<tr class="oddeven">';
// Date from // Date from
print '<td>'.dol_print_date(($productfourn->fourn_date_creation ? $productfourn->fourn_date_creation: $productfourn->date_creation), 'dayhour').'</td>'; print '<td>'.dol_print_date(($productfourn->fourn_date_creation ? $productfourn->fourn_date_creation : $productfourn->date_creation), 'dayhour').'</td>';
// Supplier // Supplier
print '<td>'.$productfourn->getSocNomUrl(1, 'supplier').'</td>'; print '<td>'.$productfourn->getSocNomUrl(1, 'supplier').'</td>';
@ -916,10 +916,10 @@ SCRIPT;
} }
// Availability // Availability
if(!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY))
{ {
$form->load_cache_availability(); $form->load_cache_availability();
$availability= $form->cache_availability[$productfourn->fk_availability]['label']; $availability = $form->cache_availability[$productfourn->fk_availability]['label'];
print '<td class="left">'.$availability.'</td>'; print '<td class="left">'.$availability.'</td>';
} }
@ -930,7 +930,7 @@ SCRIPT;
if ($conf->global->PRODUCT_USE_UNITS) { if ($conf->global->PRODUCT_USE_UNITS) {
$unit = $object->getLabelOfUnit(); $unit = $object->getLabelOfUnit();
if ($unit !== '') { if ($unit !== '') {
print '&nbsp;&nbsp;' . $langs->trans($unit); print '&nbsp;&nbsp;'.$langs->trans($unit);
} }
} }
print '</td>'; print '</td>';
@ -942,7 +942,7 @@ SCRIPT;
// Price for the quantity // Price for the quantity
print '<td class="right">'; print '<td class="right">';
print $productfourn->fourn_price?price($productfourn->fourn_price):""; print $productfourn->fourn_price ?price($productfourn->fourn_price) : "";
print '</td>'; print '</td>';
if ($conf->multicurrency->enabled) { if ($conf->multicurrency->enabled) {
@ -995,9 +995,9 @@ SCRIPT;
// Barcode type // Barcode type
print '<td align="center">'; print '<td align="center">';
$productfourn->barcode_type = !empty($productfourn->fk_barcode_type) ? $productfourn->fk_barcode_type:0; $productfourn->barcode_type = !empty($productfourn->fk_barcode_type) ? $productfourn->fk_barcode_type : 0;
$productfourn->fetch_barcode(); $productfourn->fetch_barcode();
print $productfourn->barcode_type_label?$productfourn->barcode_type_label:($productfourn->barcode?'<div class="warning">'.$langs->trans("SetDefaultBarcodeType").'<div>':''); print $productfourn->barcode_type_label ? $productfourn->barcode_type_label : ($productfourn->barcode ? '<div class="warning">'.$langs->trans("SetDefaultBarcodeType").'<div>' : '');
print '</td>'; print '</td>';
} }
@ -1007,19 +1007,19 @@ SCRIPT;
print '</td>'; print '</td>';
// Extrafields // Extrafields
$resql = $db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = " . $productfourn->product_fourn_price_id); $resql = $db->query("SELECT * FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields WHERE fk_object = ".$productfourn->product_fourn_price_id);
if (! empty($extralabels)) { if (!empty($extralabels)) {
if ($db->num_rows($resql) != 1) { if ($db->num_rows($resql) != 1) {
foreach ($extralabels as $key => $value) { foreach ($extralabels as $key => $value) {
if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {
print "<td></td>"; print "<td></td>";
} }
} }
} else { } else {
$resql = $db->fetch_object($resql); $resql = $db->fetch_object($resql);
foreach ($extralabels as $key => $value) { foreach ($extralabels as $key => $value) {
if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {
print '<td align="right">' . $extrafields->showOutputField($key, $resql->{$key}) . "</td>"; print '<td align="right">'.$extrafields->showOutputField($key, $resql->{$key})."</td>";
} }
} }
} }
@ -1027,8 +1027,8 @@ SCRIPT;
if (is_object($hookmanager)) if (is_object($hookmanager))
{ {
$parameters=array('id_pfp'=>$productfourn->product_fourn_price_id,'id_fourn'=>$id_fourn,'prod_id'=>$object->id); $parameters = array('id_pfp'=>$productfourn->product_fourn_price_id, 'id_fourn'=>$id_fourn, 'prod_id'=>$object->id);
$reshook=$hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action);
} }
// Modify-Remove // Modify-Remove

View File

@ -26,7 +26,7 @@
*/ */
// Put here all includes required by your class file // Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
@ -48,7 +48,7 @@ class Productlot extends CommonObject
/** /**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
*/ */
public $picto='barcode'; public $picto = 'barcode';
/** /**
* 0=No test on entity, 1=Test with field entity, 2=Test with link by societe * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
@ -59,14 +59,14 @@ class Productlot extends CommonObject
/** /**
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
*/ */
public $fields=array( public $fields = array(
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
'batch' =>array('type'=>'varchar(30)', 'label'=>'Batch', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'comment'=>'Batch'), 'batch' =>array('type'=>'varchar(30)', 'label'=>'Batch', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'comment'=>'Batch'),
'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20), 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500), 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501), 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
'fk_user_creat'=>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510, 'foreignkey'=>'llx_user.rowid'), 'fk_user_creat'=>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510, 'foreignkey'=>'llx_user.rowid'),
'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511) 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511)
); );
/** /**
@ -150,56 +150,56 @@ class Productlot extends CommonObject
// Put here code to add control on parameters values // Put here code to add control on parameters values
// Insert request // Insert request
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'(';
$sql.= 'entity,'; $sql .= 'entity,';
$sql.= 'fk_product,'; $sql .= 'fk_product,';
$sql.= 'batch,'; $sql .= 'batch,';
$sql.= 'eatby,'; $sql .= 'eatby,';
$sql.= 'sellby,'; $sql .= 'sellby,';
$sql.= 'datec,'; $sql .= 'datec,';
$sql.= 'fk_user_creat,'; $sql .= 'fk_user_creat,';
$sql.= 'fk_user_modif,'; $sql .= 'fk_user_modif,';
$sql.= 'import_key'; $sql .= 'import_key';
$sql .= ') VALUES ('; $sql .= ') VALUES (';
$sql .= ' '.(! isset($this->entity)?$conf->entity:$this->entity).','; $sql .= ' '.(!isset($this->entity) ? $conf->entity : $this->entity).',';
$sql .= ' '.(! isset($this->fk_product)?'NULL':$this->fk_product).','; $sql .= ' '.(!isset($this->fk_product) ? 'NULL' : $this->fk_product).',';
$sql .= ' '.(! isset($this->batch)?'NULL':"'".$this->db->escape($this->batch)."'").','; $sql .= ' '.(!isset($this->batch) ? 'NULL' : "'".$this->db->escape($this->batch)."'").',';
$sql .= ' '.(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':"'".$this->db->idate($this->eatby)."'").','; $sql .= ' '.(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'".$this->db->idate($this->eatby)."'").',';
$sql .= ' '.(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':"'".$this->db->idate($this->sellby)."'").','; $sql .= ' '.(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'".$this->db->idate($this->sellby)."'").',';
$sql .= ' '."'".$this->db->idate(dol_now())."'".','; $sql .= ' '."'".$this->db->idate(dol_now())."'".',';
$sql .= ' '.(! isset($this->fk_user_creat)?'NULL':$this->fk_user_creat).','; $sql .= ' '.(!isset($this->fk_user_creat) ? 'NULL' : $this->fk_user_creat).',';
$sql .= ' '.(! isset($this->fk_user_modif)?'NULL':$this->fk_user_modif).','; $sql .= ' '.(!isset($this->fk_user_modif) ? 'NULL' : $this->fk_user_modif).',';
$sql .= ' '.(! isset($this->import_key)?'NULL':$this->import_key); $sql .= ' '.(!isset($this->import_key) ? 'NULL' : $this->import_key);
$sql .= ')'; $sql .= ')';
$this->db->begin(); $this->db->begin();
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) { if (!$resql) {
$error ++; $error++;
$this->errors[] = 'Error ' . $this->db->lasterror(); $this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
} }
if (!$error) { if (!$error) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
// Actions on extra fields // Actions on extra fields
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{ {
$result=$this->insertExtraFields(); $result = $this->insertExtraFields();
if ($result < 0) if ($result < 0)
{ {
$error++; $error++;
} }
} }
if (! $error && ! $notrigger) { if (!$error && !$notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you // Uncomment this and change MYOBJECT to your own tag if you
// want this action to call a trigger. // want this action to call a trigger.
// Call triggers // Call triggers
$result=$this->call_trigger('PRODUCTLOT_CREATE', $user); $result = $this->call_trigger('PRODUCTLOT_CREATE', $user);
if ($result < 0) $error++; if ($result < 0) $error++;
// End call triggers // End call triggers
} }
@ -209,7 +209,7 @@ class Productlot extends CommonObject
if ($error) { if ($error) {
$this->db->rollback(); $this->db->rollback();
return - 1 * $error; return -1 * $error;
} else { } else {
$this->db->commit(); $this->db->commit();
@ -243,11 +243,11 @@ class Productlot extends CommonObject
$sql .= " t.fk_user_creat,"; $sql .= " t.fk_user_creat,";
$sql .= " t.fk_user_modif,"; $sql .= " t.fk_user_modif,";
$sql .= " t.import_key"; $sql .= " t.import_key";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
if ($product_id > 0 && $batch != '') { if ($product_id > 0 && $batch != '') {
$sql .= " WHERE t.batch = '". $this->db->escape($batch) . "' AND t.fk_product = " . $product_id; $sql .= " WHERE t.batch = '".$this->db->escape($batch)."' AND t.fk_product = ".$product_id;
} else { } else {
$sql .= ' WHERE t.rowid = ' . $id; $sql .= ' WHERE t.rowid = '.$id;
} }
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -261,7 +261,7 @@ class Productlot extends CommonObject
//$this->ref = $obj->fk_product.'_'.$obj->batch; //$this->ref = $obj->fk_product.'_'.$obj->batch;
$this->batch = $obj->batch; $this->batch = $obj->batch;
$this->entity = (!empty($obj->entity)?$obj->entity:$conf->entity); // Prevent "null" entity $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity); // Prevent "null" entity
$this->fk_product = $obj->fk_product; $this->fk_product = $obj->fk_product;
$this->eatby = $this->db->jdate($obj->eatby); $this->eatby = $this->db->jdate($obj->eatby);
$this->sellby = $this->db->jdate($obj->sellby); $this->sellby = $this->db->jdate($obj->sellby);
@ -283,10 +283,10 @@ class Productlot extends CommonObject
return 0; return 0;
} }
} else { } else {
$this->errors[] = 'Error ' . $this->db->lasterror(); $this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
return - 1; return -1;
} }
} }
@ -330,38 +330,38 @@ class Productlot extends CommonObject
if (empty($this->oldcopy)) if (empty($this->oldcopy))
{ {
$org=new self($this->db); $org = new self($this->db);
$org->fetch($this->id); $org->fetch($this->id);
$this->oldcopy=$org; $this->oldcopy = $org;
} }
// Update request // Update request
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET';
$sql .= ' entity = '.(isset($this->entity)?$this->entity:"null").','; $sql .= ' entity = '.(isset($this->entity) ? $this->entity : "null").',';
$sql .= ' fk_product = '.(isset($this->fk_product)?$this->fk_product:"null").','; $sql .= ' fk_product = '.(isset($this->fk_product) ? $this->fk_product : "null").',';
$sql .= ' batch = '.(isset($this->batch)?"'".$this->db->escape($this->batch)."'":"null").','; $sql .= ' batch = '.(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").',';
$sql .= ' eatby = '.(! isset($this->eatby) || dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').','; $sql .= ' eatby = '.(!isset($this->eatby) || dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').',';
$sql .= ' sellby = '.(! isset($this->sellby) || dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null').','; $sql .= ' sellby = '.(!isset($this->sellby) || dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null').',';
$sql .= ' datec = '.(! isset($this->datec) || dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').','; $sql .= ' datec = '.(!isset($this->datec) || dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').',';
$sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'").','; $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'").',';
$sql .= ' fk_user_creat = '.(isset($this->fk_user_creat)?$this->fk_user_creat:"null").','; $sql .= ' fk_user_creat = '.(isset($this->fk_user_creat) ? $this->fk_user_creat : "null").',';
$sql .= ' fk_user_modif = '.(isset($this->fk_user_modif)?$this->fk_user_modif:"null").','; $sql .= ' fk_user_modif = '.(isset($this->fk_user_modif) ? $this->fk_user_modif : "null").',';
$sql .= ' import_key = '.(isset($this->import_key)?$this->import_key:"null"); $sql .= ' import_key = '.(isset($this->import_key) ? $this->import_key : "null");
$sql .= ' WHERE rowid=' . $this->id; $sql .= ' WHERE rowid='.$this->id;
$this->db->begin(); $this->db->begin();
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) { if (!$resql) {
$error ++; $error++;
$this->errors[] = 'Error ' . $this->db->lasterror(); $this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
} }
// Actions on extra fields // Actions on extra fields
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{ {
$result=$this->insertExtraFields(); $result = $this->insertExtraFields();
if ($result < 0) if ($result < 0)
{ {
$error++; $error++;
@ -370,7 +370,7 @@ class Productlot extends CommonObject
if (!$error && !$notrigger) { if (!$error && !$notrigger) {
// Call triggers // Call triggers
$result=$this->call_trigger('PRODUCTLOT_MODIFY', $user); $result = $this->call_trigger('PRODUCTLOT_MODIFY', $user);
if ($result < 0) { $error++; } if ($result < 0) { $error++; }
// End call triggers // End call triggers
} }
@ -379,7 +379,7 @@ class Productlot extends CommonObject
if ($error) { if ($error) {
$this->db->rollback(); $this->db->rollback();
return - 1 * $error; return -1 * $error;
} else { } else {
$this->db->commit(); $this->db->commit();
@ -416,14 +416,14 @@ class Productlot extends CommonObject
//} //}
if (!$error) { if (!$error) {
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
$sql .= ' WHERE rowid=' . $this->id; $sql .= ' WHERE rowid='.$this->id;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) { if (!$resql) {
$error ++; $error++;
$this->errors[] = 'Error ' . $this->db->lasterror(); $this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
} }
} }
@ -431,7 +431,7 @@ class Productlot extends CommonObject
if ($error) { if ($error) {
$this->db->rollback(); $this->db->rollback();
return - 1 * $error; return -1 * $error;
} else { } else {
$this->db->commit(); $this->db->commit();
@ -469,9 +469,9 @@ class Productlot extends CommonObject
// Other options // Other options
if ($result < 0) { if ($result < 0) {
$error ++; $error++;
$this->errors = $object->errors; $this->errors = $object->errors;
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
} }
unset($object->context['createfromclone']); unset($object->context['createfromclone']);
@ -484,7 +484,7 @@ class Productlot extends CommonObject
} else { } else {
$this->db->rollback(); $this->db->rollback();
return - 1; return -1;
} }
} }
@ -539,16 +539,16 @@ class Productlot extends CommonObject
$result = ''; $result = '';
$label = '<u>' . $langs->trans("Batch") . '</u>'; $label = '<u>'.$langs->trans("Batch").'</u>';
$label.= '<div width="100%">'; $label .= '<div width="100%">';
$label.= '<b>' . $langs->trans('Batch') . ':</b> ' . $this->batch; $label .= '<b>'.$langs->trans('Batch').':</b> '.$this->batch;
if ($this->eatby) if ($this->eatby)
{ {
$label.= '<br><b>' . $langs->trans('EatByDate') . ':</b> ' . dol_print_date($this->eatby, 'day'); $label .= '<br><b>'.$langs->trans('EatByDate').':</b> '.dol_print_date($this->eatby, 'day');
} }
if ($this->sellby) if ($this->sellby)
{ {
$label.= '<br><b>' . $langs->trans('SellByDate') . ':</b> ' . dol_print_date($this->sellby, 'day'); $label .= '<br><b>'.$langs->trans('SellByDate').':</b> '.dol_print_date($this->sellby, 'day');
} }
$url = DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$this->id; $url = DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$this->id;
@ -556,31 +556,31 @@ class Productlot extends CommonObject
if ($option != 'nolink') if ($option != 'nolink')
{ {
// Add param to save lastsearch_values or not // Add param to save lastsearch_values or not
$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); $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 ($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 ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
} }
$linkclose=''; $linkclose = '';
if (empty($notooltip)) if (empty($notooltip))
{ {
if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{ {
$label=$langs->trans("ShowMyObject"); $label = $langs->trans("ShowMyObject");
$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
} }
$linkclose.=' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"'; $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
} }
else $linkclose = ($morecss?' class="'.$morecss.'"':''); else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
$linkstart = '<a href="'.$url.'"'; $linkstart = '<a href="'.$url.'"';
$linkstart.=$linkclose.'>'; $linkstart .= $linkclose.'>';
$linkend='</a>'; $linkend = '</a>';
$result .= $linkstart; $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) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result.= $this->batch; if ($withpicto != 2) $result .= $this->batch;
$result .= $linkend; $result .= $linkend;
return $result; return $result;

View File

@ -38,7 +38,7 @@ $langs->loadLangs(array('products', 'stocks', 'orders', 'productbatch'));
if ($user->socid) { if ($user->socid) {
$socid = $user->socid; $socid = $user->socid;
} }
$result=restrictedArea($user, 'produit|service'); $result = restrictedArea($user, 'produit|service');
//checks if a product has been ordered //checks if a product has been ordered
@ -62,11 +62,11 @@ if (!$sortfield) {
if (!$sortorder) { if (!$sortorder) {
$sortorder = 'ASC'; $sortorder = 'ASC';
} }
$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$offset = $limit * $page ; $offset = $limit * $page;
$listofdata=array(); $listofdata = array();
if (! empty($_SESSION['massstockmove'])) $listofdata=json_decode($_SESSION['massstockmove'], true); if (!empty($_SESSION['massstockmove'])) $listofdata = json_decode($_SESSION['massstockmove'], true);
/* /*
@ -75,17 +75,17 @@ if (! empty($_SESSION['massstockmove'])) $listofdata=json_decode($_SESSION['mass
if ($action == 'addline') if ($action == 'addline')
{ {
if (! ($id_product > 0)) if (!($id_product > 0))
{ {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
} }
if (! ($id_sw > 0)) if (!($id_sw > 0))
{ {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
} }
if (! ($id_tw > 0)) if (!($id_tw > 0))
{ {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
@ -96,16 +96,16 @@ if ($action == 'addline')
$langs->load("errors"); $langs->load("errors");
setEventMessages($langs->trans("ErrorWarehouseMustDiffers"), null, 'errors'); setEventMessages($langs->trans("ErrorWarehouseMustDiffers"), null, 'errors');
} }
if (! $qty) if (!$qty)
{ {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
} }
// Check a batch number is provided if product need it // Check a batch number is provided if product need it
if (! $error) if (!$error)
{ {
$producttmp=new Product($db); $producttmp = new Product($db);
$producttmp->fetch($id_product); $producttmp->fetch($id_product);
if ($producttmp->hasbatch()) if ($producttmp->hasbatch())
{ {
@ -120,7 +120,7 @@ if ($action == 'addline')
// TODO Check qty is ok for stock move. Note qty may not be enough yet, but we make a check now to report a warning. // TODO Check qty is ok for stock move. Note qty may not be enough yet, but we make a check now to report a warning.
// What is important is to have qty when doing action 'createmovements' // What is important is to have qty when doing action 'createmovements'
if (! $error) if (!$error)
{ {
// Warning, don't forget lines already added into the $_SESSION['massstockmove'] // Warning, don't forget lines already added into the $_SESSION['massstockmove']
if ($producttmp->hasbatch()) if ($producttmp->hasbatch())
@ -131,12 +131,12 @@ if ($action == 'addline')
} }
} }
if (! $error) if (!$error)
{ {
if (count(array_keys($listofdata)) > 0) $id=max(array_keys($listofdata)) + 1; if (count(array_keys($listofdata)) > 0) $id = max(array_keys($listofdata)) + 1;
else $id=1; else $id = 1;
$listofdata[$id]=array('id'=>$id, 'id_product'=>$id_product, 'qty'=>$qty, 'id_sw'=>$id_sw, 'id_tw'=>$id_tw, 'batch'=>$batch); $listofdata[$id] = array('id'=>$id, 'id_product'=>$id_product, 'qty'=>$qty, 'id_sw'=>$id_sw, 'id_tw'=>$id_tw, 'batch'=>$batch);
$_SESSION['massstockmove']=json_encode($listofdata); $_SESSION['massstockmove'] = json_encode($listofdata);
unset($id_product); unset($id_product);
//unset($id_sw); //unset($id_sw);
@ -147,16 +147,16 @@ if ($action == 'addline')
if ($action == 'delline' && $idline != '') if ($action == 'delline' && $idline != '')
{ {
if (! empty($listofdata[$idline])) unset($listofdata[$idline]); if (!empty($listofdata[$idline])) unset($listofdata[$idline]);
if (count($listofdata) > 0) $_SESSION['massstockmove']=json_encode($listofdata); if (count($listofdata) > 0) $_SESSION['massstockmove'] = json_encode($listofdata);
else unset($_SESSION['massstockmove']); else unset($_SESSION['massstockmove']);
} }
if ($action == 'createmovements') if ($action == 'createmovements')
{ {
$error=0; $error = 0;
if (! GETPOST("label")) if (!GETPOST("label"))
{ {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired"), $langs->transnoentitiesnoconv("MovementLabel"), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired"), $langs->transnoentitiesnoconv("MovementLabel"), null, 'errors');
@ -164,38 +164,38 @@ if ($action == 'createmovements')
$db->begin(); $db->begin();
if (! $error) if (!$error)
{ {
$product = new Product($db); $product = new Product($db);
foreach($listofdata as $key => $val) // Loop on each movement to do foreach ($listofdata as $key => $val) // Loop on each movement to do
{ {
$id=$val['id']; $id = $val['id'];
$id_product=$val['id_product']; $id_product = $val['id_product'];
$id_sw=$val['id_sw']; $id_sw = $val['id_sw'];
$id_tw=$val['id_tw']; $id_tw = $val['id_tw'];
$qty=price2num($val['qty']); $qty = price2num($val['qty']);
$batch=$val['batch']; $batch = $val['batch'];
$dlc=-1; // They are loaded later from serial $dlc = -1; // They are loaded later from serial
$dluo=-1; // They are loaded later from serial $dluo = -1; // They are loaded later from serial
if (! $error && $id_sw <> $id_tw && is_numeric($qty) && $id_product) if (!$error && $id_sw <> $id_tw && is_numeric($qty) && $id_product)
{ {
$result=$product->fetch($id_product); $result = $product->fetch($id_product);
$product->load_stock('novirtual'); // Load array product->stock_warehouse $product->load_stock('novirtual'); // Load array product->stock_warehouse
// Define value of products moved // Define value of products moved
$pricesrc=0; $pricesrc = 0;
if (! empty($product->pmp)) $pricesrc=$product->pmp; if (!empty($product->pmp)) $pricesrc = $product->pmp;
$pricedest=$pricesrc; $pricedest = $pricesrc;
//print 'price src='.$pricesrc.', price dest='.$pricedest;exit; //print 'price src='.$pricesrc.', price dest='.$pricedest;exit;
if (empty($conf->productbatch->enabled) || ! $product->hasbatch()) // If product does not need lot/serial if (empty($conf->productbatch->enabled) || !$product->hasbatch()) // If product does not need lot/serial
{ {
// Remove stock // Remove stock
$result1=$product->correct_stock( $result1 = $product->correct_stock(
$user, $user,
$id_sw, $id_sw,
$qty, $qty,
@ -211,7 +211,7 @@ if ($action == 'createmovements')
} }
// Add stock // Add stock
$result2=$product->correct_stock( $result2 = $product->correct_stock(
$user, $user,
$id_tw, $id_tw,
$qty, $qty,
@ -228,22 +228,22 @@ if ($action == 'createmovements')
} }
else else
{ {
$arraybatchinfo=$product->loadBatchInfo($batch); $arraybatchinfo = $product->loadBatchInfo($batch);
if (count($arraybatchinfo) > 0) if (count($arraybatchinfo) > 0)
{ {
$firstrecord = array_shift($arraybatchinfo); $firstrecord = array_shift($arraybatchinfo);
$dlc=$firstrecord['eatby']; $dlc = $firstrecord['eatby'];
$dluo=$firstrecord['sellby']; $dluo = $firstrecord['sellby'];
//var_dump($batch); var_dump($arraybatchinfo); var_dump($firstrecord); var_dump($dlc); var_dump($dluo); exit; //var_dump($batch); var_dump($arraybatchinfo); var_dump($firstrecord); var_dump($dlc); var_dump($dluo); exit;
} }
else else
{ {
$dlc=''; $dlc = '';
$dluo=''; $dluo = '';
} }
// Remove stock // Remove stock
$result1=$product->correct_stock_batch( $result1 = $product->correct_stock_batch(
$user, $user,
$id_sw, $id_sw,
$qty, $qty,
@ -262,7 +262,7 @@ if ($action == 'createmovements')
} }
// Add stock // Add stock
$result2=$product->correct_stock_batch( $result2 = $product->correct_stock_batch(
$user, $user,
$id_tw, $id_tw,
$qty, $qty,
@ -289,13 +289,13 @@ if ($action == 'createmovements')
} }
} }
if (! $error) if (!$error)
{ {
unset($_SESSION['massstockmove']); unset($_SESSION['massstockmove']);
$db->commit(); $db->commit();
setEventMessages($langs->trans("StockMovementRecorded"), null, 'mesgs'); setEventMessages($langs->trans("StockMovementRecorded"), null, 'mesgs');
header("Location: ".DOL_URL_ROOT.'/product/stock/index.php'); // Redirect to avoid pb when using back header("Location: ".DOL_URL_ROOT.'/product/stock/index.php'); // Redirect to avoid pb when using back
exit; exit;
} }
else else
@ -311,10 +311,10 @@ if ($action == 'createmovements')
* View * View
*/ */
$now=dol_now(); $now = dol_now();
$form=new Form($db); $form = new Form($db);
$formproduct=new FormProduct($db); $formproduct = new FormProduct($db);
$productstatic = new Product($db); $productstatic = new Product($db);
$warehousestatics = new Entrepot($db); $warehousestatics = new Entrepot($db);
$warehousestatict = new Entrepot($db); $warehousestatict = new Entrepot($db);
@ -325,16 +325,16 @@ llxHeader('', $title);
print load_fiche_titre($langs->trans("MassStockTransferShort")); print load_fiche_titre($langs->trans("MassStockTransferShort"));
$titletoadd=$langs->trans("Select"); $titletoadd = $langs->trans("Select");
$buttonrecord=$langs->trans("RecordMovement"); $buttonrecord = $langs->trans("RecordMovement");
$titletoaddnoent=$langs->transnoentitiesnoconv("Select"); $titletoaddnoent = $langs->transnoentitiesnoconv("Select");
$buttonrecordnoent=$langs->transnoentitiesnoconv("RecordMovement"); $buttonrecordnoent = $langs->transnoentitiesnoconv("RecordMovement");
print '<span class="opacitymedium">'.$langs->trans("SelectProductInAndOutWareHouse", $titletoaddnoent, $buttonrecordnoent).'</span><br>'; print '<span class="opacitymedium">'.$langs->trans("SelectProductInAndOutWareHouse", $titletoaddnoent, $buttonrecordnoent).'</span><br>';
print '<br>'."\n"; print '<br>'."\n";
// Form to add a line // Form to add a line
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">';
print '<input type="hidden" name="token" value="' .$_SESSION['newtoken'] . '">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addline">'; print '<input type="hidden" name="action" value="addline">';
@ -342,7 +342,7 @@ print '<div class="div-table-responsive-no-min">';
print '<table class="liste centpercent">'; print '<table class="liste centpercent">';
//print '<div class="tagtable centpercent">'; //print '<div class="tagtable centpercent">';
$param=''; $param = '';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print getTitleFieldOfList($langs->trans('ProductRef'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone '); print getTitleFieldOfList($langs->trans('ProductRef'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
@ -359,10 +359,10 @@ print '</tr>';
print '<tr class="oddeven">'; print '<tr class="oddeven">';
// Product // Product
print '<td class="titlefield">'; print '<td class="titlefield">';
$filtertype=0; $filtertype = 0;
if (! empty($conf->global->STOCK_SUPPORTS_SERVICES)) $filtertype=''; if (!empty($conf->global->STOCK_SUPPORTS_SERVICES)) $filtertype = '';
if ($conf->global->PRODUIT_LIMIT_SIZE <= 0) { if ($conf->global->PRODUIT_LIMIT_SIZE <= 0) {
$limit=''; $limit = '';
} }
else else
{ {
@ -394,7 +394,7 @@ print '<td class="right"><input type="submit" class="button" name="addline" valu
print '</tr>'; print '</tr>';
foreach($listofdata as $key => $val) foreach ($listofdata as $key => $val)
{ {
$productstatic->fetch($val['id_product']); $productstatic->fetch($val['id_product']);
$warehousestatics->fetch($val['id_sw']); $warehousestatics->fetch($val['id_sw']);
@ -432,12 +432,12 @@ print '<br>';
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire2">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire2">';
print '<input type="hidden" name="token" value="' .$_SESSION['newtoken'] . '">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="createmovements">'; print '<input type="hidden" name="action" value="createmovements">';
// Button to record mass movement // Button to record mass movement
$codemove=(isset($_POST["codemove"])?GETPOST("codemove", 'alpha'):dol_print_date(dol_now(), '%Y%m%d%H%M%S')); $codemove = (isset($_POST["codemove"]) ?GETPOST("codemove", 'alpha') : dol_print_date(dol_now(), '%Y%m%d%H%M%S'));
$labelmovement=GETPOST("label")?GETPOST('label'):$langs->trans("StockTransfer").' '.dol_print_date($now, '%Y-%m-%d %H:%M'); $labelmovement = GETPOST("label") ?GETPOST('label') : $langs->trans("StockTransfer").' '.dol_print_date($now, '%Y-%m-%d %H:%M');
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr>'; print '<tr>';

View File

@ -38,46 +38,46 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productstockentrepot.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productstockentrepot.class.php';
if (! empty($conf->productbatch->enabled)) { if (!empty($conf->productbatch->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
} }
if (! empty($conf->projet->enabled)) { if (!empty($conf->projet->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
} }
if (! empty($conf->variants->enabled)) { if (!empty($conf->variants->enabled)) {
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductAttribute.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductAttributeValue.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php';
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductCombination.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductCombination2ValuePair.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php';
} }
// Load translation files required by the page // Load translation files required by the page
$langs->loadlangs(array('products', 'orders', 'bills', 'stocks', 'sendings')); $langs->loadlangs(array('products', 'orders', 'bills', 'stocks', 'sendings'));
if (! empty($conf->productbatch->enabled)) $langs->load("productbatch"); if (!empty($conf->productbatch->enabled)) $langs->load("productbatch");
$backtopage=GETPOST('backtopage', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha');
$action=GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
$cancel=GETPOST('cancel', 'alpha'); $cancel = GETPOST('cancel', 'alpha');
$id=GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$ref=GETPOST('ref', 'alpha'); $ref = GETPOST('ref', 'alpha');
$stocklimit = GETPOST('seuil_stock_alerte'); $stocklimit = GETPOST('seuil_stock_alerte');
$desiredstock = GETPOST('desiredstock'); $desiredstock = GETPOST('desiredstock');
$cancel = GETPOST('cancel', 'alpha'); $cancel = GETPOST('cancel', 'alpha');
$fieldid = isset($_GET["ref"])?'ref':'rowid'; $fieldid = isset($_GET["ref"]) ? 'ref' : 'rowid';
$d_eatby=dol_mktime(0, 0, 0, $_POST['eatbymonth'], $_POST['eatbyday'], $_POST['eatbyyear']); $d_eatby = dol_mktime(0, 0, 0, $_POST['eatbymonth'], $_POST['eatbyday'], $_POST['eatbyyear']);
$d_sellby=dol_mktime(0, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']); $d_sellby = dol_mktime(0, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']);
$pdluoid=GETPOST('pdluoid', 'int'); $pdluoid = GETPOST('pdluoid', 'int');
$batchnumber=GETPOST('batch_number', 'san_alpha'); $batchnumber = GETPOST('batch_number', 'san_alpha');
if (!empty($batchnumber)) { if (!empty($batchnumber)) {
$batchnumber=trim($batchnumber); $batchnumber = trim($batchnumber);
} }
// Security check // Security check
if ($user->socid) $socid=$user->socid; if ($user->socid) $socid = $user->socid;
$result=restrictedArea($user, 'produit&stock', $id, 'product&product', '', '', $fieldid); $result = restrictedArea($user, 'produit&stock', $id, 'product&product', '', '', $fieldid);
$object = new Product($db); $object = new Product($db);
@ -86,19 +86,19 @@ $extrafields = new ExtraFields($db);
// fetch optionals attributes and labels // fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element); $extrafields->fetch_name_optionals_label($object->table_element);
if ($id > 0 || ! empty($ref)) if ($id > 0 || !empty($ref))
{ {
$result = $object->fetch($id, $ref); $result = $object->fetch($id, $ref);
} }
if(empty($id) && !empty($object->id)) $id = $object->id; if (empty($id) && !empty($object->id)) $id = $object->id;
$modulepart='product'; $modulepart = 'product';
// Get object canvas (By default, this is not defined, so standard usage of dolibarr) // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
$canvas = !empty($object->canvas)?$object->canvas:GETPOST("canvas"); $canvas = !empty($object->canvas) ? $object->canvas : GETPOST("canvas");
$objcanvas=null; $objcanvas = null;
if (! empty($canvas)) if (!empty($canvas))
{ {
require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
$objcanvas = new Canvas($db, $action); $objcanvas = new Canvas($db, $action);
@ -106,17 +106,17 @@ if (! empty($canvas))
} }
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('stockproductcard','globalcard')); $hookmanager->initHooks(array('stockproductcard', 'globalcard'));
/* /*
* Actions * Actions
*/ */
if ($cancel) $action=''; if ($cancel) $action = '';
$parameters=array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas); $parameters = array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($action == 'addlimitstockwarehouse' && !empty($user->rights->produit->creer)) if ($action == 'addlimitstockwarehouse' && !empty($user->rights->produit->creer))
@ -125,29 +125,29 @@ if ($action == 'addlimitstockwarehouse' && !empty($user->rights->produit->creer)
$desiredstock = GETPOST('desiredstock'); $desiredstock = GETPOST('desiredstock');
$maj_ok = true; $maj_ok = true;
if($seuil_stock_alerte == '') { if ($seuil_stock_alerte == '') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("StockLimit")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("StockLimit")), null, 'errors');
$maj_ok = false; $maj_ok = false;
} }
if($desiredstock == '') { if ($desiredstock == '') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DesiredStock")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DesiredStock")), null, 'errors');
$maj_ok = false; $maj_ok = false;
} }
if($maj_ok) { if ($maj_ok) {
$pse = new ProductStockEntrepot($db); $pse = new ProductStockEntrepot($db);
if ($pse->fetch(0, $id, GETPOST('fk_entrepot', 'int')) > 0) { if ($pse->fetch(0, $id, GETPOST('fk_entrepot', 'int')) > 0) {
// Update // Update
$pse->seuil_stock_alerte = $seuil_stock_alerte; $pse->seuil_stock_alerte = $seuil_stock_alerte;
$pse->desiredstock = $desiredstock; $pse->desiredstock = $desiredstock;
if($pse->update($user) > 0) setEventMessages($langs->trans('ProductStockWarehouseUpdated'), null, 'mesgs'); if ($pse->update($user) > 0) setEventMessages($langs->trans('ProductStockWarehouseUpdated'), null, 'mesgs');
} else { } else {
// Create // Create
$pse->fk_entrepot = GETPOST('fk_entrepot'); $pse->fk_entrepot = GETPOST('fk_entrepot');
$pse->fk_product = $id; $pse->fk_product = $id;
$pse->seuil_stock_alerte = GETPOST('seuil_stock_alerte'); $pse->seuil_stock_alerte = GETPOST('seuil_stock_alerte');
$pse->desiredstock = GETPOST('desiredstock'); $pse->desiredstock = GETPOST('desiredstock');
if($pse->create($user) > 0) setEventMessages($langs->trans('ProductStockWarehouseCreated'), null, 'mesgs'); if ($pse->create($user) > 0) setEventMessages($langs->trans('ProductStockWarehouseCreated'), null, 'mesgs');
} }
} }
@ -155,7 +155,7 @@ if ($action == 'addlimitstockwarehouse' && !empty($user->rights->produit->creer)
exit; exit;
} }
if($action == 'delete_productstockwarehouse' && !empty($user->rights->produit->creer)) if ($action == 'delete_productstockwarehouse' && !empty($user->rights->produit->creer))
{ {
$pse = new ProductStockEntrepot($db); $pse = new ProductStockEntrepot($db);
@ -169,61 +169,61 @@ if($action == 'delete_productstockwarehouse' && !empty($user->rights->produit->c
if ($action == 'setseuil_stock_alerte' && !empty($user->rights->produit->creer)) if ($action == 'setseuil_stock_alerte' && !empty($user->rights->produit->creer))
{ {
$object = new Product($db); $object = new Product($db);
$result=$object->fetch($id); $result = $object->fetch($id);
$object->seuil_stock_alerte=$stocklimit; $object->seuil_stock_alerte = $stocklimit;
$result=$object->update($object->id, $user, 0, 'update'); $result = $object->update($object->id, $user, 0, 'update');
if ($result < 0) if ($result < 0)
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
//else //else
// setEventMessages($lans->trans("SavedRecordSuccessfully"), null, 'mesgs'); // setEventMessages($lans->trans("SavedRecordSuccessfully"), null, 'mesgs');
$action=''; $action = '';
} }
// Set desired stock // Set desired stock
if ($action == 'setdesiredstock' && !empty($user->rights->produit->creer)) if ($action == 'setdesiredstock' && !empty($user->rights->produit->creer))
{ {
$object = new Product($db); $object = new Product($db);
$result=$object->fetch($id); $result = $object->fetch($id);
$object->desiredstock=$desiredstock; $object->desiredstock = $desiredstock;
$result=$object->update($object->id, $user, 0, 'update'); $result = $object->update($object->id, $user, 0, 'update');
if ($result < 0) if ($result < 0)
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$action=''; $action = '';
} }
// Correct stock // Correct stock
if ($action == "correct_stock" && ! $cancel) if ($action == "correct_stock" && !$cancel)
{ {
if (! (GETPOST("id_entrepot") > 0)) if (!(GETPOST("id_entrepot") > 0))
{ {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
$error++; $error++;
$action='correction'; $action = 'correction';
} }
if (! GETPOST("nbpiece")) if (!GETPOST("nbpiece"))
{ {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
$error++; $error++;
$action='correction'; $action = 'correction';
} }
if (! empty($conf->productbatch->enabled)) if (!empty($conf->productbatch->enabled))
{ {
$object = new Product($db); $object = new Product($db);
$result=$object->fetch($id); $result = $object->fetch($id);
if ($object->hasbatch() && ! $batchnumber) if ($object->hasbatch() && !$batchnumber)
{ {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors');
$error++; $error++;
$action='correction'; $action = 'correction';
} }
} }
if (! $error) if (!$error)
{ {
$priceunit=price2num(GETPOST("unitprice")); $priceunit = price2num(GETPOST("unitprice"));
if (is_numeric(GETPOST("nbpiece")) && $id) if (is_numeric(GETPOST("nbpiece")) && $id)
{ {
$origin_element = ''; $origin_element = '';
@ -237,16 +237,16 @@ if ($action == "correct_stock" && ! $cancel)
if (empty($object)) { if (empty($object)) {
$object = new Product($db); $object = new Product($db);
$result=$object->fetch($id); $result = $object->fetch($id);
} }
if ($object->hasbatch()) if ($object->hasbatch())
{ {
$result=$object->correct_stock_batch( $result = $object->correct_stock_batch(
$user, $user,
GETPOST("id_entrepot"), GETPOST("id_entrepot"),
GETPOST("nbpiece"), GETPOST("nbpiece"),
GETPOST("mouvement"), GETPOST("mouvement"),
GETPOST("label"), // label movement GETPOST("label"), // label movement
$priceunit, $priceunit,
$d_eatby, $d_eatby,
$d_sellby, $d_sellby,
@ -254,11 +254,11 @@ if ($action == "correct_stock" && ! $cancel)
GETPOST('inventorycode'), GETPOST('inventorycode'),
$origin_element, $origin_element,
$origin_id $origin_id
); // We do not change value of stock for a correction ); // We do not change value of stock for a correction
} }
else else
{ {
$result=$object->correct_stock( $result = $object->correct_stock(
$user, $user,
GETPOST("id_entrepot"), GETPOST("id_entrepot"),
GETPOST("nbpiece"), GETPOST("nbpiece"),
@ -268,7 +268,7 @@ if ($action == "correct_stock" && ! $cancel)
GETPOST('inventorycode'), GETPOST('inventorycode'),
$origin_element, $origin_element,
$origin_id $origin_id
); // We do not change value of stock for a correction ); // We do not change value of stock for a correction
} }
if ($result > 0) if ($result > 0)
@ -287,61 +287,61 @@ if ($action == "correct_stock" && ! $cancel)
else else
{ {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$action='correction'; $action = 'correction';
} }
} }
} }
} }
// Transfer stock from a warehouse to another warehouse // Transfer stock from a warehouse to another warehouse
if ($action == "transfert_stock" && ! $cancel) if ($action == "transfert_stock" && !$cancel)
{ {
if (! (GETPOST("id_entrepot", 'int') > 0) || ! (GETPOST("id_entrepot_destination", 'int') > 0)) if (!(GETPOST("id_entrepot", 'int') > 0) || !(GETPOST("id_entrepot_destination", 'int') > 0))
{ {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
$error++; $error++;
$action='transfert'; $action = 'transfert';
} }
if (! GETPOST("nbpiece", 'int')) if (!GETPOST("nbpiece", 'int'))
{ {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
$error++; $error++;
$action='transfert'; $action = 'transfert';
} }
if (GETPOST("id_entrepot", 'int') == GETPOST("id_entrepot_destination", 'int')) if (GETPOST("id_entrepot", 'int') == GETPOST("id_entrepot_destination", 'int'))
{ {
setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors'); setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors');
$error++; $error++;
$action='transfert'; $action = 'transfert';
} }
if (! empty($conf->productbatch->enabled)) if (!empty($conf->productbatch->enabled))
{ {
$object = new Product($db); $object = new Product($db);
$result=$object->fetch($id); $result = $object->fetch($id);
if ($object->hasbatch() && ! $batchnumber) if ($object->hasbatch() && !$batchnumber)
{ {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors');
$error++; $error++;
$action='transfert'; $action = 'transfert';
} }
} }
if (! $error) if (!$error)
{ {
if ($id) if ($id)
{ {
$object = new Product($db); $object = new Product($db);
$result=$object->fetch($id); $result = $object->fetch($id);
$db->begin(); $db->begin();
$object->load_stock('novirtual'); // Load array product->stock_warehouse $object->load_stock('novirtual'); // Load array product->stock_warehouse
// Define value of products moved // Define value of products moved
$pricesrc=0; $pricesrc = 0;
if (isset($object->pmp)) $pricesrc=$object->pmp; if (isset($object->pmp)) $pricesrc = $object->pmp;
$pricedest=$pricesrc; $pricedest = $pricesrc;
if ($object->hasbatch()) if ($object->hasbatch())
{ {
@ -349,13 +349,13 @@ if ($action == "transfert_stock" && ! $cancel)
if ($pdluoid > 0) if ($pdluoid > 0)
{ {
$result=$pdluo->fetch($pdluoid); $result = $pdluo->fetch($pdluoid);
if ($result) if ($result)
{ {
$srcwarehouseid=$pdluo->warehouseid; $srcwarehouseid = $pdluo->warehouseid;
$batch=$pdluo->batch; $batch = $pdluo->batch;
$eatby=$pdluo->eatby; $eatby = $pdluo->eatby;
$sellby=$pdluo->sellby; $sellby = $pdluo->sellby;
} }
else else
{ {
@ -365,16 +365,16 @@ if ($action == "transfert_stock" && ! $cancel)
} }
else else
{ {
$srcwarehouseid=GETPOST('id_entrepot', 'int'); $srcwarehouseid = GETPOST('id_entrepot', 'int');
$batch=$batchnumber; $batch = $batchnumber;
$eatby=$d_eatby; $eatby = $d_eatby;
$sellby=$d_sellby; $sellby = $d_sellby;
} }
if (! $error) if (!$error)
{ {
// Remove stock // Remove stock
$result1=$object->correct_stock_batch( $result1 = $object->correct_stock_batch(
$user, $user,
$srcwarehouseid, $srcwarehouseid,
GETPOST("nbpiece", 'int'), GETPOST("nbpiece", 'int'),
@ -386,10 +386,10 @@ if ($action == "transfert_stock" && ! $cancel)
); );
if ($result1 < 0) $error++; if ($result1 < 0) $error++;
} }
if (! $error) if (!$error)
{ {
// Add stock // Add stock
$result2=$object->correct_stock_batch( $result2 = $object->correct_stock_batch(
$user, $user,
GETPOST("id_entrepot_destination", 'int'), GETPOST("id_entrepot_destination", 'int'),
GETPOST("nbpiece", 'int'), GETPOST("nbpiece", 'int'),
@ -404,10 +404,10 @@ if ($action == "transfert_stock" && ! $cancel)
} }
else else
{ {
if (! $error) if (!$error)
{ {
// Remove stock // Remove stock
$result1=$object->correct_stock( $result1 = $object->correct_stock(
$user, $user,
GETPOST("id_entrepot"), GETPOST("id_entrepot"),
GETPOST("nbpiece"), GETPOST("nbpiece"),
@ -418,10 +418,10 @@ if ($action == "transfert_stock" && ! $cancel)
); );
if ($result1 < 0) $error++; if ($result1 < 0) $error++;
} }
if (! $error) if (!$error)
{ {
// Add stock // Add stock
$result2=$object->correct_stock( $result2 = $object->correct_stock(
$user, $user,
GETPOST("id_entrepot_destination"), GETPOST("id_entrepot_destination"),
GETPOST("nbpiece"), GETPOST("nbpiece"),
@ -435,7 +435,7 @@ if ($action == "transfert_stock" && ! $cancel)
} }
if (! $error && $result1 >= 0 && $result2 >= 0) if (!$error && $result1 >= 0 && $result2 >= 0)
{ {
$db->commit(); $db->commit();
@ -454,7 +454,7 @@ if ($action == "transfert_stock" && ! $cancel)
{ {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$db->rollback(); $db->rollback();
$action='transfert'; $action = 'transfert';
} }
} }
} }
@ -464,24 +464,24 @@ if ($action == "transfert_stock" && ! $cancel)
if ($action == 'updateline' && GETPOST('save') == $langs->trans('Save')) if ($action == 'updateline' && GETPOST('save') == $langs->trans('Save'))
{ {
$pdluo = new Productbatch($db); $pdluo = new Productbatch($db);
$result=$pdluo->fetch(GETPOST('pdluoid', 'int')); $result = $pdluo->fetch(GETPOST('pdluoid', 'int'));
if ($result>0) if ($result > 0)
{ {
if ($pdluo->id) if ($pdluo->id)
{ {
if ((! GETPOST("sellby")) && (! GETPOST("eatby")) && (! $batchnumber)) { if ((!GETPOST("sellby")) && (!GETPOST("eatby")) && (!$batchnumber)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("atleast1batchfield")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("atleast1batchfield")), null, 'errors');
} }
else else
{ {
$d_eatby=dol_mktime(0, 0, 0, $_POST['eatbymonth'], $_POST['eatbyday'], $_POST['eatbyyear']); $d_eatby = dol_mktime(0, 0, 0, $_POST['eatbymonth'], $_POST['eatbyday'], $_POST['eatbyyear']);
$d_sellby=dol_mktime(0, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']); $d_sellby = dol_mktime(0, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']);
$pdluo->batch=$batchnumber; $pdluo->batch = $batchnumber;
$pdluo->eatby=$d_eatby; $pdluo->eatby = $d_eatby;
$pdluo->sellby=$d_sellby; $pdluo->sellby = $d_sellby;
$result=$pdluo->update($user); $result = $pdluo->update($user);
if ($result<0) if ($result < 0)
{ {
setEventMessages($pdluo->error, $pdluo->errors, 'errors'); setEventMessages($pdluo->error, $pdluo->errors, 'errors');
} }
@ -507,8 +507,8 @@ if ($action == 'updateline' && GETPOST('save') == $langs->trans('Save'))
*/ */
$form = new Form($db); $form = new Form($db);
$formproduct=new FormProduct($db); $formproduct = new FormProduct($db);
if (! empty($conf->projet->enabled)) $formproject=new FormProjets($db); if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db);
if ($id > 0 || $ref) if ($id > 0 || $ref)
{ {
@ -524,22 +524,22 @@ if ($id > 0 || $ref)
$shortlabel = dol_trunc($object->label, 16); $shortlabel = dol_trunc($object->label, 16);
if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT))
{ {
$title = $langs->trans('Product')." ". $shortlabel ." - ".$langs->trans('Stock'); $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Stock');
$helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos'; $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
} }
if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE))
{ {
$title = $langs->trans('Service')." ". $shortlabel ." - ".$langs->trans('Stock'); $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Stock');
$helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios'; $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
} }
llxHeader('', $title, $helpurl); llxHeader('', $title, $helpurl);
if ($result > 0) if ($result > 0)
{ {
$head=product_prepare_head($object); $head = product_prepare_head($object);
$titre=$langs->trans("CardProduct".$object->type); $titre = $langs->trans("CardProduct".$object->type);
$picto=($object->type==Product::TYPE_SERVICE?'service':'product'); $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
dol_fiche_head($head, 'stock', $titre, -1, $picto); dol_fiche_head($head, 'stock', $titre, -1, $picto);
@ -548,7 +548,7 @@ if ($id > 0 || $ref)
$linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$shownav = 1; $shownav = 1;
if ($user->socid && ! in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0;
dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
@ -557,22 +557,22 @@ if ($id > 0 || $ref)
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table class="border tableforfield" width="100%">'; print '<table class="border tableforfield" width="100%">';
if (! $variants) { if (!$variants) {
if ($conf->productbatch->enabled) { if ($conf->productbatch->enabled) {
print '<tr><td class="titlefield">' . $langs->trans("ManageLotSerial") . '</td><td>'; print '<tr><td class="titlefield">'.$langs->trans("ManageLotSerial").'</td><td>';
print $object->getLibStatut(0, 2); print $object->getLibStatut(0, 2);
print '</td></tr>'; print '</td></tr>';
} }
// PMP // PMP
print '<tr><td class="titlefield">' . $langs->trans("AverageUnitPricePMP") . '</td>'; print '<tr><td class="titlefield">'.$langs->trans("AverageUnitPricePMP").'</td>';
print '<td>'; print '<td>';
if ($object->pmp > 0) print price($object->pmp) . ' ' . $langs->trans("HT"); if ($object->pmp > 0) print price($object->pmp).' '.$langs->trans("HT");
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Minimum Price // Minimum Price
print '<tr><td>' . $langs->trans("BuyingPriceMin") . '</td>'; print '<tr><td>'.$langs->trans("BuyingPriceMin").'</td>';
print '<td>'; print '<td>';
$product_fourn = new ProductFournisseur($db); $product_fourn = new ProductFournisseur($db);
if ($product_fourn->find_min_price_product_fournisseur($object->id) > 0) { if ($product_fourn->find_min_price_product_fournisseur($object->id) > 0) {
@ -583,103 +583,103 @@ if ($id > 0 || $ref)
if (empty($conf->global->PRODUIT_MULTIPRICES)) { if (empty($conf->global->PRODUIT_MULTIPRICES)) {
// Price // Price
print '<tr><td>' . $langs->trans("SellingPrice") . '</td><td>'; print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>';
if ($object->price_base_type == 'TTC') { if ($object->price_base_type == 'TTC') {
print price($object->price_ttc) . ' ' . $langs->trans($object->price_base_type); print price($object->price_ttc).' '.$langs->trans($object->price_base_type);
} else { } else {
print price($object->price) . ' ' . $langs->trans($object->price_base_type); print price($object->price).' '.$langs->trans($object->price_base_type);
} }
print '</td></tr>'; print '</td></tr>';
// Price minimum // Price minimum
print '<tr><td>' . $langs->trans("MinPrice") . '</td><td>'; print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
if ($object->price_base_type == 'TTC') { if ($object->price_base_type == 'TTC') {
print price($object->price_min_ttc) . ' ' . $langs->trans($object->price_base_type); print price($object->price_min_ttc).' '.$langs->trans($object->price_base_type);
} else { } else {
print price($object->price_min) . ' ' . $langs->trans($object->price_base_type); print price($object->price_min).' '.$langs->trans($object->price_base_type);
} }
print '</td></tr>'; print '</td></tr>';
} else { } else {
// Price // Price
print '<tr><td>' . $langs->trans("SellingPrice") . '</td><td>'; print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>';
print $langs->trans("Variable"); print $langs->trans("Variable");
print '</td></tr>'; print '</td></tr>';
// Price minimum // Price minimum
print '<tr><td>' . $langs->trans("MinPrice") . '</td><td>'; print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
print $langs->trans("Variable"); print $langs->trans("Variable");
print '</td></tr>'; print '</td></tr>';
} }
// Stock alert threshold // Stock alert threshold
print '<tr><td>' . $form->editfieldkey($form->textwithpicto($langs->trans("StockLimit"), $langs->trans("StockLimitDesc"), 1), 'seuil_stock_alerte', $object->seuil_stock_alerte, $object, $user->rights->produit->creer) . '</td><td>'; print '<tr><td>'.$form->editfieldkey($form->textwithpicto($langs->trans("StockLimit"), $langs->trans("StockLimitDesc"), 1), 'seuil_stock_alerte', $object->seuil_stock_alerte, $object, $user->rights->produit->creer).'</td><td>';
print $form->editfieldval("StockLimit", 'seuil_stock_alerte', $object->seuil_stock_alerte, $object, $user->rights->produit->creer, 'string'); print $form->editfieldval("StockLimit", 'seuil_stock_alerte', $object->seuil_stock_alerte, $object, $user->rights->produit->creer, 'string');
print '</td></tr>'; print '</td></tr>';
// Hook formObject // Hook formObject
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
// Desired stock // Desired stock
print '<tr><td>' . $form->editfieldkey($form->textwithpicto($langs->trans("DesiredStock"), $langs->trans("DesiredStockDesc"), 1), 'desiredstock', $object->desiredstock, $object, $user->rights->produit->creer); print '<tr><td>'.$form->editfieldkey($form->textwithpicto($langs->trans("DesiredStock"), $langs->trans("DesiredStockDesc"), 1), 'desiredstock', $object->desiredstock, $object, $user->rights->produit->creer);
print '</td><td>'; print '</td><td>';
print $form->editfieldval("DesiredStock", 'desiredstock', $object->desiredstock, $object, $user->rights->produit->creer, 'string'); print $form->editfieldval("DesiredStock", 'desiredstock', $object->desiredstock, $object, $user->rights->produit->creer, 'string');
print '</td></tr>'; print '</td></tr>';
// Real stock // Real stock
$text_stock_options = $langs->trans("RealStockDesc") . '<br>'; $text_stock_options = $langs->trans("RealStockDesc").'<br>';
$text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen") . '<br>'; $text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen").'<br>';
$text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) ? $langs->trans("DeStockOnShipment") . '<br>' : ''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) ? $langs->trans("DeStockOnShipment").'<br>' : '');
$text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) ? $langs->trans("DeStockOnValidateOrder") . '<br>' : ''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) ? $langs->trans("DeStockOnValidateOrder").'<br>' : '');
$text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_BILL) ? $langs->trans("DeStockOnBill") . '<br>' : ''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_BILL) ? $langs->trans("DeStockOnBill").'<br>' : '');
$text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) ? $langs->trans("ReStockOnBill") . '<br>' : ''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) ? $langs->trans("ReStockOnBill").'<br>' : '');
$text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) ? $langs->trans("ReStockOnValidateOrder") . '<br>' : ''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) ? $langs->trans("ReStockOnValidateOrder").'<br>' : '');
$text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) ? $langs->trans("ReStockOnDispatchOrder") . '<br>' : ''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) ? $langs->trans("ReStockOnDispatchOrder").'<br>' : '');
$text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)?$langs->trans("StockOnReception").'<br>':''); $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE) ? $langs->trans("StockOnReception").'<br>' : '');
print '<tr><td>'; print '<tr><td>';
print $form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1); print $form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1);
print '</td>'; print '</td>';
print '<td>' . price2num($object->stock_reel, 'MS'); print '<td>'.price2num($object->stock_reel, 'MS');
if ($object->seuil_stock_alerte != '' && ($object->stock_reel < $object->seuil_stock_alerte)) print ' ' . img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte)); if ($object->seuil_stock_alerte != '' && ($object->stock_reel < $object->seuil_stock_alerte)) print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte));
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
$stocktheo = price2num($object->stock_theorique, 'MS'); $stocktheo = price2num($object->stock_theorique, 'MS');
$found = 0; $found = 0;
$helpondiff = '<strong>' . $langs->trans("StockDiffPhysicTeoric") . ':</strong><br>'; $helpondiff = '<strong>'.$langs->trans("StockDiffPhysicTeoric").':</strong><br>';
// Number of customer orders running // Number of customer orders running
if (!empty($conf->commande->enabled)) { if (!empty($conf->commande->enabled)) {
if ($found) $helpondiff .= '<br>'; else $found = 1; if ($found) $helpondiff .= '<br>'; else $found = 1;
$helpondiff .= $langs->trans("ProductQtyInCustomersOrdersRunning") . ': ' . $object->stats_commande['qty']; $helpondiff .= $langs->trans("ProductQtyInCustomersOrdersRunning").': '.$object->stats_commande['qty'];
$result = $object->load_stats_commande(0, '0', 1); $result = $object->load_stats_commande(0, '0', 1);
if ($result < 0) dol_print_error($db, $object->error); if ($result < 0) dol_print_error($db, $object->error);
$helpondiff .= ' (' . $langs->trans("ProductQtyInDraft") . ': ' . $object->stats_commande['qty'] . ')'; $helpondiff .= ' ('.$langs->trans("ProductQtyInDraft").': '.$object->stats_commande['qty'].')';
} }
// Number of product from customer order already sent (partial shipping) // Number of product from customer order already sent (partial shipping)
if (!empty($conf->expedition->enabled)) { if (!empty($conf->expedition->enabled)) {
if ($found) $helpondiff .= '<br>'; else $found = 1; if ($found) $helpondiff .= '<br>'; else $found = 1;
$result = $object->load_stats_sending(0, '2', 1); $result = $object->load_stats_sending(0, '2', 1);
$helpondiff .= $langs->trans("ProductQtyInShipmentAlreadySent") . ': ' . $object->stats_expedition['qty']; $helpondiff .= $langs->trans("ProductQtyInShipmentAlreadySent").': '.$object->stats_expedition['qty'];
} }
// Number of supplier order running // Number of supplier order running
if (!empty($conf->fournisseur->enabled)) { if (!empty($conf->fournisseur->enabled)) {
if ($found) $helpondiff .= '<br>'; else $found = 1; if ($found) $helpondiff .= '<br>'; else $found = 1;
$result = $object->load_stats_commande_fournisseur(0, '3,4', 1); $result = $object->load_stats_commande_fournisseur(0, '3,4', 1);
$helpondiff .= $langs->trans("ProductQtyInSuppliersOrdersRunning") . ': ' . $object->stats_commande_fournisseur['qty']; $helpondiff .= $langs->trans("ProductQtyInSuppliersOrdersRunning").': '.$object->stats_commande_fournisseur['qty'];
$result = $object->load_stats_commande_fournisseur(0, '0,1,2', 1); $result = $object->load_stats_commande_fournisseur(0, '0,1,2', 1);
if ($result < 0) dol_print_error($db, $object->error); if ($result < 0) dol_print_error($db, $object->error);
$helpondiff .= ' (' . $langs->trans("ProductQtyInDraftOrWaitingApproved") . ': ' . $object->stats_commande_fournisseur['qty'] . ')'; $helpondiff .= ' ('.$langs->trans("ProductQtyInDraftOrWaitingApproved").': '.$object->stats_commande_fournisseur['qty'].')';
} }
// Number of product from supplier order already received (partial receipt) // Number of product from supplier order already received (partial receipt)
if (!empty($conf->fournisseur->enabled)) { if (!empty($conf->fournisseur->enabled)) {
if ($found) $helpondiff .= '<br>'; else $found = 1; if ($found) $helpondiff .= '<br>'; else $found = 1;
$helpondiff .= $langs->trans("ProductQtyInSuppliersShipmentAlreadyRecevied") . ': ' . $object->stats_reception['qty']; $helpondiff .= $langs->trans("ProductQtyInSuppliersShipmentAlreadyRecevied").': '.$object->stats_reception['qty'];
} }
// Calculating a theorical value // Calculating a theorical value
@ -689,7 +689,7 @@ if ($id > 0 || $ref)
print "<td>"; print "<td>";
//print (empty($stocktheo)?0:$stocktheo); //print (empty($stocktheo)?0:$stocktheo);
print $form->textwithpicto((empty($stocktheo) ? 0 : $stocktheo), $helpondiff); print $form->textwithpicto((empty($stocktheo) ? 0 : $stocktheo), $helpondiff);
if ($object->seuil_stock_alerte != '' && ($object->stock_theorique < $object->seuil_stock_alerte)) print ' ' . img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte)); if ($object->seuil_stock_alerte != '' && ($object->stock_theorique < $object->seuil_stock_alerte)) print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte));
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -697,8 +697,8 @@ if ($id > 0 || $ref)
if (!empty($user->rights->stock->mouvement->lire)) if (!empty($user->rights->stock->mouvement->lire))
{ {
$sql = "SELECT max(m.datem) as datem"; $sql = "SELECT max(m.datem) as datem";
$sql .= " FROM " . MAIN_DB_PREFIX . "stock_mouvement as m"; $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
$sql .= " WHERE m.fk_product = '" . $object->id . "'"; $sql .= " WHERE m.fk_product = '".$object->id."'";
$resqlbis = $db->query($sql); $resqlbis = $db->query($sql);
if ($resqlbis) { if ($resqlbis) {
$obj = $db->fetch_object($resqlbis); $obj = $db->fetch_object($resqlbis);
@ -706,12 +706,12 @@ if ($id > 0 || $ref)
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
print '<tr><td class="tdtop">' . $langs->trans("LastMovement") . '</td><td>'; print '<tr><td class="tdtop">'.$langs->trans("LastMovement").'</td><td>';
if ($lastmovementdate) { if ($lastmovementdate) {
print dol_print_date($lastmovementdate, 'dayhour') . ' '; print dol_print_date($lastmovementdate, 'dayhour').' ';
print '(<a href="' . DOL_URL_ROOT . '/product/stock/movement_list.php?idproduct=' . $object->id . '">' . $langs->trans("FullList") . '</a>)'; print '(<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?idproduct='.$object->id.'">'.$langs->trans("FullList").'</a>)';
} else { } else {
print '<a href="' . DOL_URL_ROOT . '/product/stock/movement_list.php?idproduct=' . $object->id . '">' . $langs->trans("None") . '</a>'; print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?idproduct='.$object->id.'">'.$langs->trans("None").'</a>';
} }
print "</td></tr>"; print "</td></tr>";
} }
@ -750,9 +750,9 @@ else
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if (empty($reshook)) if (empty($reshook))
{ {
if (empty($action) && $object->id) if (empty($action) && $object->id)
@ -761,33 +761,33 @@ if (empty($reshook))
if ($user->rights->stock->mouvement->creer) if ($user->rights->stock->mouvement->creer)
{ {
if (! $variants || ! empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) { if (!$variants || !empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) {
print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=correction">' . $langs->trans("CorrectStock") . '</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=correction">'.$langs->trans("CorrectStock").'</a>';
} }
else else
{ {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ActionAvailableOnVariantProductOnly").'">' . $langs->trans("CorrectStock") . '</a>'; print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ActionAvailableOnVariantProductOnly").'">'.$langs->trans("CorrectStock").'</a>';
} }
} }
else else
{ {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">' . $langs->trans("CorrectStock") . '</a>'; print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CorrectStock").'</a>';
} }
//if (($user->rights->stock->mouvement->creer) && ! $object->hasbatch()) //if (($user->rights->stock->mouvement->creer) && ! $object->hasbatch())
if ($user->rights->stock->mouvement->creer) if ($user->rights->stock->mouvement->creer)
{ {
if (! $variants || ! empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) { if (!$variants || !empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) {
print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=transfert">' . $langs->trans("TransferStock") . '</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=transfert">'.$langs->trans("TransferStock").'</a>';
} }
else else
{ {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ActionAvailableOnVariantProductOnly").'">' . $langs->trans("TransferStock") . '</a>'; print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ActionAvailableOnVariantProductOnly").'">'.$langs->trans("TransferStock").'</a>';
} }
} }
else else
{ {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">' . $langs->trans("CorrectStock") . '</a>'; print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CorrectStock").'</a>';
} }
print '</div>'; print '</div>';
@ -795,7 +795,7 @@ if (empty($reshook))
} }
if (! $variants) { if (!$variants) {
/* /*
* Stock detail (by warehouse). May go down into batch details. * Stock detail (by warehouse). May go down into batch details.
*/ */
@ -804,18 +804,18 @@ if (! $variants) {
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td colspan="4">' . $langs->trans("Warehouse") . '</td>'; print '<td colspan="4">'.$langs->trans("Warehouse").'</td>';
print '<td class="right">' . $langs->trans("NumberOfUnit") . '</td>'; print '<td class="right">'.$langs->trans("NumberOfUnit").'</td>';
print '<td class="right">' . $langs->trans("AverageUnitPricePMPShort") . '</td>'; print '<td class="right">'.$langs->trans("AverageUnitPricePMPShort").'</td>';
print '<td class="right">' . $langs->trans("EstimatedStockValueShort") . '</td>'; print '<td class="right">'.$langs->trans("EstimatedStockValueShort").'</td>';
print '<td class="right">' . $langs->trans("SellPriceMin") . '</td>'; print '<td class="right">'.$langs->trans("SellPriceMin").'</td>';
print '<td class="right">' . $langs->trans("EstimatedStockValueSellShort") . '</td>'; print '<td class="right">'.$langs->trans("EstimatedStockValueSellShort").'</td>';
print '</tr>'; print '</tr>';
if ((!empty($conf->productbatch->enabled)) && $object->hasbatch()) { if ((!empty($conf->productbatch->enabled)) && $object->hasbatch()) {
print '<tr class="liste_titre"><td width="10%"></td>'; print '<tr class="liste_titre"><td width="10%"></td>';
print '<td class="right" width="10%">' . $langs->trans("batch_number") . '</td>'; print '<td class="right" width="10%">'.$langs->trans("batch_number").'</td>';
print '<td class="center" width="10%">' . $langs->trans("EatByDate") . '</td>'; print '<td class="center" width="10%">'.$langs->trans("EatByDate").'</td>';
print '<td class="center" width="10%">' . $langs->trans("SellByDate") . '</td>'; print '<td class="center" width="10%">'.$langs->trans("SellByDate").'</td>';
print '<td></td>'; print '<td></td>';
print '<td></td>'; print '<td></td>';
print '<td></td>'; print '<td></td>';
@ -825,13 +825,13 @@ if (! $variants) {
} }
$sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut, ps.reel, ps.rowid as product_stock_id, p.pmp"; $sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut, ps.reel, ps.rowid as product_stock_id, p.pmp";
$sql .= " FROM " . MAIN_DB_PREFIX . "entrepot as e,"; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
$sql .= " " . MAIN_DB_PREFIX . "product_stock as ps"; $sql .= " ".MAIN_DB_PREFIX."product_stock as ps";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = ps.fk_product"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product";
$sql .= " WHERE ps.reel != 0"; $sql .= " WHERE ps.reel != 0";
$sql .= " AND ps.fk_entrepot = e.rowid"; $sql .= " AND ps.fk_entrepot = e.rowid";
$sql .= " AND e.entity IN (" . getEntity('stock') . ")"; $sql .= " AND e.entity IN (".getEntity('stock').")";
$sql .= " AND ps.fk_product = " . $object->id; $sql .= " AND ps.fk_product = ".$object->id;
$sql .= " ORDER BY e.ref"; $sql .= " ORDER BY e.ref";
$entrepotstatic = new Entrepot($db); $entrepotstatic = new Entrepot($db);
@ -859,12 +859,12 @@ if (! $variants) {
$stock_real = price2num($obj->reel, 'MS'); $stock_real = price2num($obj->reel, 'MS');
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td colspan="4">' . $entrepotstatic->getNomUrl(1) . '</td>'; print '<td colspan="4">'.$entrepotstatic->getNomUrl(1).'</td>';
print '<td class="right">' . $stock_real . ($stock_real < 0 ? ' ' . img_warning() : '') . '</td>'; print '<td class="right">'.$stock_real.($stock_real < 0 ? ' '.img_warning() : '').'</td>';
// PMP // PMP
print '<td class="right">' . (price2num($object->pmp) ? price2num($object->pmp, 'MU') : '') . '</td>'; print '<td class="right">'.(price2num($object->pmp) ? price2num($object->pmp, 'MU') : '').'</td>';
// Value purchase // Value purchase
print '<td class="right">' . (price2num($object->pmp) ? price(price2num($object->pmp * $obj->reel, 'MT')) : '') . '</td>'; print '<td class="right">'.(price2num($object->pmp) ? price(price2num($object->pmp * $obj->reel, 'MT')) : '').'</td>';
// Sell price // Sell price
print '<td class="right">'; print '<td class="right">';
if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($object->price, 'MU'), 1); if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($object->price, 'MU'), 1);
@ -872,7 +872,7 @@ if (! $variants) {
print '</td>'; print '</td>';
// Value sell // Value sell
print '<td class="right">'; print '<td class="right">';
if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($object->price * $obj->reel, 'MT'), 1) . '</td>'; if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($object->price * $obj->reel, 'MT'), 1).'</td>';
else print $langs->trans("Variable"); else print $langs->trans("Variable");
print '</tr>'; print '</tr>';
$total += $obj->reel; $total += $obj->reel;
@ -890,27 +890,27 @@ if (! $variants) {
$product_lot_static->sellby = $pdluo->sellby; $product_lot_static->sellby = $pdluo->sellby;
if ($action == 'editline' && GETPOST('lineid', 'int') == $pdluo->id) { //Current line edit if ($action == 'editline' && GETPOST('lineid', 'int') == $pdluo->id) { //Current line edit
print "\n" . '<tr>'; print "\n".'<tr>';
print '<td colspan="9">'; print '<td colspan="9">';
print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="pdluoid" value="' . $pdluo->id . '"><input type="hidden" name="action" value="updateline"><input type="hidden" name="id" value="' . $id . '"><table class="noborder centpercent"><tr><td width="10%"></td>'; print '<input type="hidden" name="pdluoid" value="'.$pdluo->id.'"><input type="hidden" name="action" value="updateline"><input type="hidden" name="id" value="'.$id.'"><table class="noborder centpercent"><tr><td width="10%"></td>';
print '<td class="right" width="10%"><input type="text" name="batch_number" value="' . $pdluo->batch . '"></td>'; print '<td class="right" width="10%"><input type="text" name="batch_number" value="'.$pdluo->batch.'"></td>';
print '<td class="center" width="10%">'; print '<td class="center" width="10%">';
print $form->selectDate($pdluo->eatby, 'eatby', '', '', 1, '', 1, 0); print $form->selectDate($pdluo->eatby, 'eatby', '', '', 1, '', 1, 0);
print '</td>'; print '</td>';
print '<td class="center" width="10%">'; print '<td class="center" width="10%">';
print $form->selectDate($pdluo->sellby, 'sellby', '', '', 1, '', 1, 0); print $form->selectDate($pdluo->sellby, 'sellby', '', '', 1, '', 1, 0);
print '</td>'; print '</td>';
print '<td class="right" width="10%">' . $pdluo->qty . ($pdluo->qty < 0 ? ' ' . img_warning() : '') . '</td>'; print '<td class="right" width="10%">'.$pdluo->qty.($pdluo->qty < 0 ? ' '.img_warning() : '').'</td>';
print '<td colspan="4"><input type="submit" class="button" id="savelinebutton" name="save" value="' . $langs->trans("Save") . '">'; print '<td colspan="4"><input type="submit" class="button" id="savelinebutton" name="save" value="'.$langs->trans("Save").'">';
print '<input type="submit" class="button" id="cancellinebutton" name="Cancel" value="' . $langs->trans("Cancel") . '"></td></tr>'; print '<input type="submit" class="button" id="cancellinebutton" name="Cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>'; print '</table>';
print '</form>'; print '</form>';
print '</td></tr>'; print '</td></tr>';
} else { } else {
print "\n" . '<tr><td class="right">'; print "\n".'<tr><td class="right">';
print img_picto($langs->trans("Tranfer"), 'uparrow', 'class="hideonsmartphone"') . ' '; print img_picto($langs->trans("Tranfer"), 'uparrow', 'class="hideonsmartphone"').' ';
print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;id_entrepot=' . $entrepotstatic->id . '&amp;action=transfert&amp;pdluoid=' . $pdluo->id . '">' . $langs->trans("TransferStock") . '</a>'; print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;id_entrepot='.$entrepotstatic->id.'&amp;action=transfert&amp;pdluoid='.$pdluo->id.'">'.$langs->trans("TransferStock").'</a>';
// Disabled, because edition of stock content must use the "Correct stock menu". // Disabled, because edition of stock content must use the "Correct stock menu".
// Do not use this, or data will be wrong (bad tracking of movement label, inventory code, ... // Do not use this, or data will be wrong (bad tracking of movement label, inventory code, ...
//print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=editline&amp;lineid='.$pdluo->id.'#'.$pdluo->id.'">'; //print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=editline&amp;lineid='.$pdluo->id.'#'.$pdluo->id.'">';
@ -918,9 +918,9 @@ if (! $variants) {
print '<td class="right">'; print '<td class="right">';
print $product_lot_static->getNomUrl(1); print $product_lot_static->getNomUrl(1);
print '</td>'; print '</td>';
print '<td class="center">' . dol_print_date($pdluo->eatby, 'day') . '</td>'; print '<td class="center">'.dol_print_date($pdluo->eatby, 'day').'</td>';
print '<td class="center">' . dol_print_date($pdluo->sellby, 'day') . '</td>'; print '<td class="center">'.dol_print_date($pdluo->sellby, 'day').'</td>';
print '<td class="right">' . $pdluo->qty . ($pdluo->qty < 0 ? ' ' . img_warning() : '') . '</td>'; print '<td class="right">'.$pdluo->qty.($pdluo->qty < 0 ? ' '.img_warning() : '').'</td>';
print '<td colspan="4"></td>'; print '<td colspan="4"></td>';
print '</tr>'; print '</tr>';
} }
@ -931,10 +931,10 @@ if (! $variants) {
} else dol_print_error($db); } else dol_print_error($db);
// Total line // Total line
print '<tr class="liste_total"><td class="right liste_total" colspan="4">' . $langs->trans("Total") . ':</td>'; print '<tr class="liste_total"><td class="right liste_total" colspan="4">'.$langs->trans("Total").':</td>';
print '<td class="liste_total right">' . price2num($total, 'MS') . '</td>'; print '<td class="liste_total right">'.price2num($total, 'MS').'</td>';
print '<td class="liste_total right">'; print '<td class="liste_total right">';
print ($totalwithpmp ? price(price2num($totalvalue / $totalwithpmp, 'MU')) : '&nbsp;'); // This value may have rounding errors print ($totalwithpmp ? price(price2num($totalvalue / $totalwithpmp, 'MU')) : '&nbsp;'); // This value may have rounding errors
print '</td>'; print '</td>';
// Value purchase // Value purchase
print '<td class="liste_total right">'; print '<td class="liste_total right">';
@ -959,21 +959,21 @@ if (! $variants) {
print load_fiche_titre($langs->trans('AddNewProductStockWarehouse')); print load_fiche_titre($langs->trans('AddNewProductStockWarehouse'));
if (!empty($user->rights->produit->creer)) { if (!empty($user->rights->produit->creer)) {
print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="action" value="addlimitstockwarehouse">'; print '<input type="hidden" name="action" value="addlimitstockwarehouse">';
print '<input type="hidden" name="id" value="' . $id . '">'; print '<input type="hidden" name="id" value="'.$id.'">';
} }
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
if (!empty($user->rights->produit->creer)) { if (!empty($user->rights->produit->creer)) {
print '<tr class="liste_titre"><td width="40%">' . $formproduct->selectWarehouses('', 'fk_entrepot') . '</td>'; print '<tr class="liste_titre"><td width="40%">'.$formproduct->selectWarehouses('', 'fk_entrepot').'</td>';
print '<td class="right"><input name="seuil_stock_alerte" type="text" placeholder="' . $langs->trans("StockLimit") . '" /></td>'; print '<td class="right"><input name="seuil_stock_alerte" type="text" placeholder="'.$langs->trans("StockLimit").'" /></td>';
print '<td class="right"><input name="desiredstock" type="text" placeholder="' . $langs->trans("DesiredStock") . '" /></td>'; print '<td class="right"><input name="desiredstock" type="text" placeholder="'.$langs->trans("DesiredStock").'" /></td>';
print '<td class="right"><input type="submit" value="' . $langs->trans('Save') . '" class="button" /></td>'; print '<td class="right"><input type="submit" value="'.$langs->trans('Save').'" class="button" /></td>';
print '</tr>'; print '</tr>';
} else { } else {
print '<tr class="liste_titre"><td width="40%">' . $langs->trans("Warehouse") . '</td>'; print '<tr class="liste_titre"><td width="40%">'.$langs->trans("Warehouse").'</td>';
print '<td class="right">' . $langs->trans("StockLimit") . '</td>'; print '<td class="right">'.$langs->trans("StockLimit").'</td>';
print '<td class="right">' . $langs->trans("DesiredStock") . '</td>'; print '<td class="right">'.$langs->trans("DesiredStock").'</td>';
print '</tr>'; print '</tr>';
} }
@ -985,11 +985,11 @@ if (! $variants) {
foreach ($lines as $line) { foreach ($lines as $line) {
$ent = new Entrepot($db); $ent = new Entrepot($db);
$ent->fetch($line['fk_entrepot']); $ent->fetch($line['fk_entrepot']);
print '<tr class="oddeven"><td width="40%">' . $ent->getNomUrl(3) . '</td>'; print '<tr class="oddeven"><td width="40%">'.$ent->getNomUrl(3).'</td>';
print '<td class="right">' . $line['seuil_stock_alerte'] . '</td>'; print '<td class="right">'.$line['seuil_stock_alerte'].'</td>';
print '<td class="right">' . $line['desiredstock'] . '</td>'; print '<td class="right">'.$line['desiredstock'].'</td>';
if (!empty($user->rights->produit->creer)) { if (!empty($user->rights->produit->creer)) {
print '<td class="right"><a href="?id=' . $id . '&fk_productstockwarehouse=' . $line['id'] . '&action=delete_productstockwarehouse">' . img_delete() . '</a></td>'; print '<td class="right"><a href="?id='.$id.'&fk_productstockwarehouse='.$line['id'].'&action=delete_productstockwarehouse">'.img_delete().'</a></td>';
} }
print '</tr>'; print '</tr>';
} }
@ -1035,12 +1035,12 @@ if (! $variants) {
if (count($productCombinations)) if (count($productCombinations))
{ {
$stock_total= 0; $stock_total = 0;
foreach ($productCombinations as $currcomb) foreach ($productCombinations as $currcomb)
{ {
$prodstatic->fetch($currcomb->fk_product_child); $prodstatic->fetch($currcomb->fk_product_child);
$prodstatic->load_stock(); $prodstatic->load_stock();
$stock_total+=$prodstatic->stock_reel; $stock_total += $prodstatic->stock_reel;
?> ?>
<tr class="oddeven"> <tr class="oddeven">
<td><?php echo $prodstatic->getNomUrl(1) ?></td> <td><?php echo $prodstatic->getNomUrl(1) ?></td>

View File

@ -41,7 +41,7 @@ $langs->loadLangs(array('products', 'stocks', 'orders'));
if ($user->socid) { if ($user->socid) {
$socid = $user->socid; $socid = $user->socid;
} }
$result=restrictedArea($user, 'produit|service'); $result = restrictedArea($user, 'produit|service');
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('stockreplenishlist')); $hookmanager->initHooks(array('stockreplenishlist'));
@ -51,7 +51,7 @@ $hookmanager->initHooks(array('stockreplenishlist'));
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$sref = GETPOST('sref', 'alpha'); $sref = GETPOST('sref', 'alpha');
$snom = GETPOST('snom', 'alpha'); $snom = GETPOST('snom', 'alpha');
$sall = trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml')); $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
$type = GETPOST('type', 'int'); $type = GETPOST('type', 'int');
$tobuy = GETPOST('tobuy', 'int'); $tobuy = GETPOST('tobuy', 'int');
$salert = GETPOST('salert', 'alpha'); $salert = GETPOST('salert', 'alpha');
@ -68,8 +68,8 @@ $sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOST('page', 'int'); $page = GETPOST('page', 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$offset = $limit * $page ; $offset = $limit * $page;
if (!$sortfield) { if (!$sortfield) {
$sortfield = 'p.ref'; $sortfield = 'p.ref';
@ -80,20 +80,20 @@ if (!$sortorder) {
} }
// Define virtualdiffersfromphysical // Define virtualdiffersfromphysical
$virtualdiffersfromphysical=0; $virtualdiffersfromphysical = 0;
if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
|| ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
|| ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
|| !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)
|| !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))
{ {
$virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs. $virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs.
} }
$usevirtualstock=0; $usevirtualstock = 0;
if ($mode == 'virtual') $usevirtualstock=1; if ($mode == 'virtual') $usevirtualstock = 1;
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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');
/* /*
@ -106,9 +106,9 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
$snom = ''; $snom = '';
$sal = ''; $sal = '';
$salert = ''; $salert = '';
$draftorder=''; $draftorder = '';
} }
if($draftorder == 'on') $draftchecked = "checked"; if ($draftorder == 'on') $draftchecked = "checked";
// Create orders // Create orders
if ($action == 'order' && isset($_POST['valid'])) if ($action == 'order' && isset($_POST['valid']))
@ -122,19 +122,19 @@ if ($action == 'order' && isset($_POST['valid']))
$db->begin(); $db->begin();
$suppliers = array(); $suppliers = array();
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
$productsupplier = new ProductFournisseur($db); $productsupplier = new ProductFournisseur($db);
for ($i = 0; $i < $linecount; $i++) for ($i = 0; $i < $linecount; $i++)
{ {
if (GETPOST('choose' . $i, 'alpha') === 'on' && GETPOST('fourn' . $i, 'int') > 0) if (GETPOST('choose'.$i, 'alpha') === 'on' && GETPOST('fourn'.$i, 'int') > 0)
{ {
//one line //one line
$box = $i; $box = $i;
$supplierpriceid = GETPOST('fourn'.$i, 'int'); $supplierpriceid = GETPOST('fourn'.$i, 'int');
//get all the parameters needed to create a line //get all the parameters needed to create a line
$qty = GETPOST('tobuy'.$i, 'int'); $qty = GETPOST('tobuy'.$i, 'int');
$idprod=$productsupplier->get_buyprice($supplierpriceid, $qty); $idprod = $productsupplier->get_buyprice($supplierpriceid, $qty);
$res=$productsupplier->fetch($idprod); $res = $productsupplier->fetch($idprod);
if ($res && $idprod > 0) if ($res && $idprod > 0)
{ {
if ($qty) if ($qty)
@ -146,12 +146,12 @@ if ($action == 'order' && isset($_POST['valid']))
//$product = new Product($db); //$product = new Product($db);
//$product->fetch($obj->fk_product); //$product->fetch($obj->fk_product);
if (! empty($conf->global->MAIN_MULTILANGS)) if (!empty($conf->global->MAIN_MULTILANGS))
{ {
$productsupplier->getMultiLangs(); $productsupplier->getMultiLangs();
} }
$line->desc = $productsupplier->description; $line->desc = $productsupplier->description;
if (! empty($conf->global->MAIN_MULTILANGS)) if (!empty($conf->global->MAIN_MULTILANGS))
{ {
// TODO Get desc in language of thirdparty // TODO Get desc in language of thirdparty
} }
@ -175,11 +175,11 @@ if ($action == 'order' && isset($_POST['valid']))
} }
else else
{ {
$error=$db->lasterror(); $error = $db->lasterror();
dol_print_error($db); dol_print_error($db);
} }
unset($_POST['fourn' . $i]); unset($_POST['fourn'.$i]);
} }
unset($_POST[$i]); unset($_POST[$i]);
} }
@ -193,12 +193,12 @@ if ($action == 'order' && isset($_POST['valid']))
$order = new CommandeFournisseur($db); $order = new CommandeFournisseur($db);
// Check if an order for the supplier exists // Check if an order for the supplier exists
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur"; $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur";
$sql.= " WHERE fk_soc = ".$suppliersid[$i]; $sql .= " WHERE fk_soc = ".$suppliersid[$i];
$sql.= " AND source = 42 AND fk_statut = 0"; $sql .= " AND source = 42 AND fk_statut = 0";
$sql.= " AND entity IN (".getEntity('commande_fournisseur').")"; $sql .= " AND entity IN (".getEntity('commande_fournisseur').")";
$sql.= " ORDER BY date_creation DESC"; $sql .= " ORDER BY date_creation DESC";
$resql = $db->query($sql); $resql = $db->query($sql);
if($resql && $db->num_rows($resql) > 0) { if ($resql && $db->num_rows($resql) > 0) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$order->fetch($obj->rowid); $order->fetch($obj->rowid);
foreach ($supplier['lines'] as $line) { foreach ($supplier['lines'] as $line) {
@ -226,7 +226,7 @@ if ($action == 'order' && isset($_POST['valid']))
} }
if ($result < 0) { if ($result < 0) {
$fail++; $fail++;
$msg = $langs->trans('OrderFail') . "&nbsp;:&nbsp;"; $msg = $langs->trans('OrderFail')."&nbsp;:&nbsp;";
$msg .= $order->error; $msg .= $order->error;
setEventMessages($msg, null, 'errors'); setEventMessages($msg, null, 'errors');
} else { } else {
@ -245,7 +245,7 @@ if ($action == 'order' && isset($_POST['valid']))
$id = $order->create($user); $id = $order->create($user);
if ($id < 0) { if ($id < 0) {
$fail++; $fail++;
$msg = $langs->trans('OrderFail') . "&nbsp;:&nbsp;"; $msg = $langs->trans('OrderFail')."&nbsp;:&nbsp;";
$msg .= $order->error; $msg .= $order->error;
setEventMessages($msg, null, 'errors'); setEventMessages($msg, null, 'errors');
} }
@ -253,9 +253,9 @@ if ($action == 'order' && isset($_POST['valid']))
} }
} }
if($errorQty) setEventMessages($langs->trans('ErrorOrdersNotCreatedQtyTooLow'), null, 'warnings'); if ($errorQty) setEventMessages($langs->trans('ErrorOrdersNotCreatedQtyTooLow'), null, 'warnings');
if (! $fail && $id) if (!$fail && $id)
{ {
$db->commit(); $db->commit();
@ -286,45 +286,45 @@ $prod = new Product($db);
$title = $langs->trans('Status'); $title = $langs->trans('Status');
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) { if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
$sqldesiredtock=$db->ifsql("pse.desiredstock IS NULL", "p.desiredstock", "pse.desiredstock"); $sqldesiredtock = $db->ifsql("pse.desiredstock IS NULL", "p.desiredstock", "pse.desiredstock");
$sqlalertstock=$db->ifsql("pse.seuil_stock_alerte IS NULL", "p.seuil_stock_alerte", "pse.seuil_stock_alerte"); $sqlalertstock = $db->ifsql("pse.seuil_stock_alerte IS NULL", "p.seuil_stock_alerte", "pse.seuil_stock_alerte");
} else { } else {
$sqldesiredtock='p.desiredstock'; $sqldesiredtock = 'p.desiredstock';
$sqlalertstock='p.seuil_stock_alerte'; $sqlalertstock = 'p.seuil_stock_alerte';
} }
$sql = 'SELECT p.rowid, p.ref, p.label, p.description, p.price,'; $sql = 'SELECT p.rowid, p.ref, p.label, p.description, p.price,';
$sql.= ' p.price_ttc, p.price_base_type,p.fk_product_type,'; $sql .= ' p.price_ttc, p.price_base_type,p.fk_product_type,';
$sql.= ' p.tms as datem, p.duration, p.tobuy,'; $sql .= ' p.tms as datem, p.duration, p.tobuy,';
$sql.= ' p.desiredstock, p.seuil_stock_alerte,'; $sql .= ' p.desiredstock, p.seuil_stock_alerte,';
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) { if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
$sql.= ' pse.desiredstock as desiredstockpse, pse.seuil_stock_alerte as seuil_stock_alertepse,'; $sql .= ' pse.desiredstock as desiredstockpse, pse.seuil_stock_alerte as seuil_stock_alertepse,';
} }
$sql.= ' '.$sqldesiredtock.' as desiredstockcombined, '.$sqlalertstock.' as seuil_stock_alertecombined,'; $sql .= ' '.$sqldesiredtock.' as desiredstockcombined, '.$sqlalertstock.' as seuil_stock_alertecombined,';
$sql.= ' SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").') as stock_physique'; $sql .= ' SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").') as stock_physique';
// Add fields from hooks // Add fields from hooks
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint; $sql .= $hookmanager->resPrint;
$sql.= ' FROM ' . MAIN_DB_PREFIX . 'product as p'; $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p';
$sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_stock as s'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s';
$sql.= ' ON (p.rowid = s.fk_product AND s.fk_entrepot IN (SELECT ent.rowid FROM '.MAIN_DB_PREFIX.'entrepot AS ent WHERE ent.entity IN('.getEntity('stock').')))'; $sql .= ' ON (p.rowid = s.fk_product AND s.fk_entrepot IN (SELECT ent.rowid FROM '.MAIN_DB_PREFIX.'entrepot AS ent WHERE ent.entity IN('.getEntity('stock').')))';
if ($fk_supplier > 0) { if ($fk_supplier > 0) {
$sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price pfp ON (pfp.fk_product = p.rowid AND pfp.fk_soc = '.$fk_supplier.')'; $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price pfp ON (pfp.fk_product = p.rowid AND pfp.fk_soc = '.$fk_supplier.')';
} }
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) { if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_warehouse_properties AS pse ON (p.rowid = pse.fk_product AND pse.fk_entrepot = '.$fk_entrepot.')'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_warehouse_properties AS pse ON (p.rowid = pse.fk_product AND pse.fk_entrepot = '.$fk_entrepot.')';
} }
// Add fields from hooks // Add fields from hooks
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('printFieldListJoin', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListJoin', $parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint; $sql .= $hookmanager->resPrint;
$sql.= ' WHERE p.entity IN (' . getEntity('product') . ')'; $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
if ($sall) $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall); if ($sall) $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall);
// if the type is not 1, we show all products (type = 0,2,3) // if the type is not 1, we show all products (type = 0,2,3)
if (dol_strlen($type)) { if (dol_strlen($type)) {
@ -334,83 +334,83 @@ if (dol_strlen($type)) {
$sql .= ' AND p.fk_product_type <> 1'; $sql .= ' AND p.fk_product_type <> 1';
} }
} }
if ($sref) $sql.=natural_search('p.ref', $sref); if ($sref) $sql .= natural_search('p.ref', $sref);
if ($snom) $sql.=natural_search('p.label', $snom); if ($snom) $sql .= natural_search('p.label', $snom);
$sql.= ' AND p.tobuy = 1'; $sql .= ' AND p.tobuy = 1';
if (!empty($canvas)) $sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"'; if (!empty($canvas)) $sql .= ' AND p.canvas = "'.$db->escape($canvas).'"';
$sql.= ' GROUP BY p.rowid, p.ref, p.label, p.description, p.price'; $sql .= ' GROUP BY p.rowid, p.ref, p.label, p.description, p.price';
$sql.= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms'; $sql .= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
$sql.= ', p.duration, p.tobuy'; $sql .= ', p.duration, p.tobuy';
$sql.= ', p.desiredstock'; $sql .= ', p.desiredstock';
$sql.= ', p.seuil_stock_alerte'; $sql .= ', p.seuil_stock_alerte';
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) { if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
$sql.= ', pse.desiredstock' ; $sql .= ', pse.desiredstock';
$sql.= ', pse.seuil_stock_alerte' ; $sql .= ', pse.seuil_stock_alerte';
} }
$sql.= ', s.fk_product'; $sql .= ', s.fk_product';
if ($usevirtualstock) if ($usevirtualstock)
{ {
$sqlCommandesCli = "(SELECT ".$db->ifsql("SUM(cd.qty) IS NULL", "0", "SUM(cd.qty)")." as qty"; $sqlCommandesCli = "(SELECT ".$db->ifsql("SUM(cd.qty) IS NULL", "0", "SUM(cd.qty)")." as qty";
$sqlCommandesCli.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sqlCommandesCli .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sqlCommandesCli.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON (c.rowid = cd.fk_commande)"; $sqlCommandesCli .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON (c.rowid = cd.fk_commande)";
$sqlCommandesCli.= " WHERE c.entity IN (".getEntity('commande').")"; $sqlCommandesCli .= " WHERE c.entity IN (".getEntity('commande').")";
$sqlCommandesCli.= " AND cd.fk_product = p.rowid"; $sqlCommandesCli .= " AND cd.fk_product = p.rowid";
$sqlCommandesCli.= " AND c.fk_statut IN (1,2))"; $sqlCommandesCli .= " AND c.fk_statut IN (1,2))";
$sqlExpeditionsCli = "(SELECT ".$db->ifsql("SUM(ed.qty) IS NULL", "0", "SUM(ed.qty)")." as qty"; $sqlExpeditionsCli = "(SELECT ".$db->ifsql("SUM(ed.qty) IS NULL", "0", "SUM(ed.qty)")." as qty";
$sqlExpeditionsCli.= " FROM ".MAIN_DB_PREFIX."expedition as e"; $sqlExpeditionsCli .= " FROM ".MAIN_DB_PREFIX."expedition as e";
$sqlExpeditionsCli.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet as ed ON (ed.fk_expedition = e.rowid)"; $sqlExpeditionsCli .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet as ed ON (ed.fk_expedition = e.rowid)";
$sqlExpeditionsCli.= " LEFT JOIN ".MAIN_DB_PREFIX."commandedet as cd ON (cd.rowid = ed.fk_origin_line)"; $sqlExpeditionsCli .= " LEFT JOIN ".MAIN_DB_PREFIX."commandedet as cd ON (cd.rowid = ed.fk_origin_line)";
$sqlExpeditionsCli.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON (c.rowid = cd.fk_commande)"; $sqlExpeditionsCli .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON (c.rowid = cd.fk_commande)";
$sqlExpeditionsCli.= " WHERE e.entity IN (".getEntity('expedition').")"; $sqlExpeditionsCli .= " WHERE e.entity IN (".getEntity('expedition').")";
$sqlExpeditionsCli.= " AND cd.fk_product = p.rowid"; $sqlExpeditionsCli .= " AND cd.fk_product = p.rowid";
$sqlExpeditionsCli.= " AND c.fk_statut IN (1,2))"; $sqlExpeditionsCli .= " AND c.fk_statut IN (1,2))";
$sqlCommandesFourn = "(SELECT ".$db->ifsql("SUM(cd.qty) IS NULL", "0", "SUM(cd.qty)")." as qty"; $sqlCommandesFourn = "(SELECT ".$db->ifsql("SUM(cd.qty) IS NULL", "0", "SUM(cd.qty)")." as qty";
$sqlCommandesFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; $sqlCommandesFourn .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd";
$sqlCommandesFourn.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; $sqlCommandesFourn .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
$sqlCommandesFourn.= " WHERE c.rowid = cd.fk_commande"; $sqlCommandesFourn .= " WHERE c.rowid = cd.fk_commande";
$sqlCommandesFourn.= " AND c.entity IN (".getEntity('supplier_order').")"; $sqlCommandesFourn .= " AND c.entity IN (".getEntity('supplier_order').")";
$sqlCommandesFourn.= " AND cd.fk_product = p.rowid"; $sqlCommandesFourn .= " AND cd.fk_product = p.rowid";
$sqlCommandesFourn.= " AND c.fk_statut IN (3,4))"; $sqlCommandesFourn .= " AND c.fk_statut IN (3,4))";
$sqlReceptionFourn = "(SELECT ".$db->ifsql("SUM(fd.qty) IS NULL", "0", "SUM(fd.qty)")." as qty"; $sqlReceptionFourn = "(SELECT ".$db->ifsql("SUM(fd.qty) IS NULL", "0", "SUM(fd.qty)")." as qty";
$sqlReceptionFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf"; $sqlReceptionFourn .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
$sqlReceptionFourn.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd ON (fd.fk_commande = cf.rowid)"; $sqlReceptionFourn .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd ON (fd.fk_commande = cf.rowid)";
$sqlReceptionFourn.= " WHERE cf.entity IN (".getEntity('supplier_order').")"; $sqlReceptionFourn .= " WHERE cf.entity IN (".getEntity('supplier_order').")";
$sqlReceptionFourn.= " AND fd.fk_product = p.rowid"; $sqlReceptionFourn .= " AND fd.fk_product = p.rowid";
$sqlReceptionFourn.= " AND cf.fk_statut IN (3,4))"; $sqlReceptionFourn .= " AND cf.fk_statut IN (3,4))";
$sql.= ' HAVING (('.$sqldesiredtock.' >= 0 AND ('.$sqldesiredtock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; $sql .= ' HAVING (('.$sqldesiredtock.' >= 0 AND ('.$sqldesiredtock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))'; $sql .= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))';
$sql.= ' OR ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; $sql .= ' OR ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.'))))'; $sql .= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.'))))';
if ($salert == 'on') // Option to see when stock is lower than alert if ($salert == 'on') // Option to see when stock is lower than alert
{ {
$sql.= ' AND ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; $sql .= ' AND ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))'; $sql .= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))';
$alertchecked = 'checked'; $alertchecked = 'checked';
} }
} else { } else {
$sql.= ' HAVING (('.$sqldesiredtock.' >= 0 AND ('.$sqldesiredtock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))'; $sql .= ' HAVING (('.$sqldesiredtock.' >= 0 AND ('.$sqldesiredtock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
$sql.= ' OR ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))))'; $sql .= ' OR ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))))';
if ($salert == 'on') // Option to see when stock is lower than alert if ($salert == 'on') // Option to see when stock is lower than alert
{ {
$sql.= ' AND ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))'; $sql .= ' AND ('.$sqlalertstock.' >= 0 AND ('.$sqlalertstock.' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
$alertchecked = 'checked'; $alertchecked = 'checked';
} }
} }
// Add where from hooks // Add where from hooks
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint; $sql .= $hookmanager->resPrint;
$sql.= $db->order($sortfield, $sortorder); $sql .= $db->order($sortfield, $sortorder);
$sql.= $db->plimit($limit + 1, $offset); $sql .= $db->plimit($limit + 1, $offset);
//print $sql; //print $sql;
$resql = $db->query($sql); $resql = $db->query($sql);
@ -473,8 +473,8 @@ print '<div class="inline-block valignmiddle" style="padding-right: 20px;">';
print $langs->trans('Supplier').' '.$form->select_company($fk_supplier, 'fk_supplier', 'fournisseur=1', 1); print $langs->trans('Supplier').' '.$form->select_company($fk_supplier, 'fk_supplier', 'fournisseur=1', 1);
print '</div>'; print '</div>';
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
if (empty($reshook)) print $hookmanager->resPrint; if (empty($reshook)) print $hookmanager->resPrint;
print '<div class="inline-block valignmiddle">'; print '<div class="inline-block valignmiddle">';
@ -484,13 +484,13 @@ print '</div>';
print '</form>'; print '</form>';
if ($sref || $snom || $sall || $salert || $draftorder || GETPOST('search', 'alpha')) { if ($sref || $snom || $sall || $salert || $draftorder || GETPOST('search', 'alpha')) {
$filters = '&sref=' . $sref . '&snom=' . $snom; $filters = '&sref='.$sref.'&snom='.$snom;
$filters .= '&sall=' . $sall; $filters .= '&sall='.$sall;
$filters .= '&salert=' . $salert; $filters .= '&salert='.$salert;
$filters .= '&draftorder=' . $draftorder; $filters .= '&draftorder='.$draftorder;
$filters .= '&mode=' . $mode; $filters .= '&mode='.$mode;
$filters .= '&fk_supplier=' . $fk_supplier; $filters .= '&fk_supplier='.$fk_supplier;
$filters .= '&fk_entrepot=' . $fk_entrepot; $filters .= '&fk_entrepot='.$fk_entrepot;
print_barre_liste( print_barre_liste(
$texte, $texte,
$page, $page,
@ -502,14 +502,14 @@ if ($sref || $snom || $sall || $salert || $draftorder || GETPOST('search', 'alph
$num $num
); );
} else { } else {
$filters = '&sref=' . $sref . '&snom=' . $snom; $filters = '&sref='.$sref.'&snom='.$snom;
$filters .= '&fourn_id=' . $fourn_id; $filters .= '&fourn_id='.$fourn_id;
$filters .= (isset($type)?'&type=' . $type:''); $filters .= (isset($type) ? '&type='.$type : '');
$filters .= '&=' . $salert; $filters .= '&='.$salert;
$filters .= '&draftorder=' . $draftorder; $filters .= '&draftorder='.$draftorder;
$filters .= '&mode=' . $mode; $filters .= '&mode='.$mode;
$filters .= '&fk_supplier=' . $fk_supplier; $filters .= '&fk_supplier='.$fk_supplier;
$filters .= '&fk_entrepot=' . $fk_entrepot; $filters .= '&fk_entrepot='.$fk_entrepot;
print_barre_liste( print_barre_liste(
$texte, $texte,
$page, $page,
@ -522,33 +522,33 @@ if ($sref || $snom || $sall || $salert || $draftorder || GETPOST('search', 'alph
); );
} }
print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="liste centpercent">'; print '<table class="liste centpercent">';
$param = (isset($type)? '&type=' . $type : ''); $param = (isset($type) ? '&type='.$type : '');
$param .= '&fourn_id=' . $fourn_id . '&snom='. $snom . '&salert=' . $salert . '&draftorder='.$draftorder; $param .= '&fourn_id='.$fourn_id.'&snom='.$snom.'&salert='.$salert.'&draftorder='.$draftorder;
$param .= '&sref=' . $sref; $param .= '&sref='.$sref;
$param .= '&mode=' . $mode; $param .= '&mode='.$mode;
$param .= '&fk_supplier=' . $fk_supplier; $param .= '&fk_supplier='.$fk_supplier;
$param .= '&fk_entrepot=' . $fk_entrepot; $param .= '&fk_entrepot='.$fk_entrepot;
$stocklabel = $langs->trans('Stock'); $stocklabel = $langs->trans('Stock');
if ($usevirtualstock == 1) $stocklabel = $langs->trans('VirtualStock'); if ($usevirtualstock == 1) $stocklabel = $langs->trans('VirtualStock');
if ($usevirtualstock == 0) $stocklabel = $langs->trans('PhysicalStock'); if ($usevirtualstock == 0) $stocklabel = $langs->trans('PhysicalStock');
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0)
{ {
$stocklabel.=' ('.$langs->trans("AllWarehouses").')'; $stocklabel .= ' ('.$langs->trans("AllWarehouses").')';
} }
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">'. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">'.
'<input type="hidden" name="token" value="' .$_SESSION['newtoken'] . '">'. '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'.
'<input type="hidden" name="fk_supplier" value="' . $fk_supplier . '">'. '<input type="hidden" name="fk_supplier" value="'.$fk_supplier.'">'.
'<input type="hidden" name="fk_entrepot" value="' .$fk_entrepot . '">'. '<input type="hidden" name="fk_entrepot" value="'.$fk_entrepot.'">'.
'<input type="hidden" name="sortfield" value="' . $sortfield . '">'. '<input type="hidden" name="sortfield" value="'.$sortfield.'">'.
'<input type="hidden" name="sortorder" value="' . $sortorder . '">'. '<input type="hidden" name="sortorder" value="'.$sortorder.'">'.
'<input type="hidden" name="type" value="' . $type . '">'. '<input type="hidden" name="type" value="'.$type.'">'.
'<input type="hidden" name="linecount" value="' . $num . '">'. '<input type="hidden" name="linecount" value="'.$num.'">'.
'<input type="hidden" name="action" value="order">'. '<input type="hidden" name="action" value="order">'.
'<input type="hidden" name="mode" value="' . $mode . '">'; '<input type="hidden" name="mode" value="'.$mode.'">';
// Fields title search // Fields title search
print '<tr class="liste_titre_filter">'; print '<tr class="liste_titre_filter">';
@ -558,16 +558,16 @@ print '<td class="liste_titre"><input class="flat" type="text" name="snom" size=
if (!empty($conf->service->enabled) && $type == 1) print '<td class="liste_titre">&nbsp;</td>'; if (!empty($conf->service->enabled) && $type == 1) print '<td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre">&nbsp;</td>'; print '<td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre right">&nbsp;</td>'; print '<td class="liste_titre right">&nbsp;</td>';
print '<td class="liste_titre right">' . $langs->trans('AlertOnly') . '&nbsp;<input type="checkbox" id="salert" name="salert" ' . (!empty($alertchecked)?$alertchecked:'') . '></td>'; print '<td class="liste_titre right">'.$langs->trans('AlertOnly').'&nbsp;<input type="checkbox" id="salert" name="salert" '.(!empty($alertchecked) ? $alertchecked : '').'></td>';
print '<td class="liste_titre right">' . $langs->trans('IncludeAlsoDraftOrders') . '&nbsp;<input type="checkbox" id="draftorder" name="draftorder" ' . (!empty($draftchecked)?$draftchecked:'') . '></td>'; print '<td class="liste_titre right">'.$langs->trans('IncludeAlsoDraftOrders').'&nbsp;<input type="checkbox" id="draftorder" name="draftorder" '.(!empty($draftchecked) ? $draftchecked : '').'></td>';
print '<td class="liste_titre">&nbsp;</td>'; print '<td class="liste_titre">&nbsp;</td>';
// Fields from hook // Fields from hook
$parameters=array('param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder); $parameters = array('param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
$reshook=$hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
print '<td class="liste_titre maxwidthsearch">'; print '<td class="liste_titre maxwidthsearch">';
$searchpicto=$form->showFilterAndCheckAddButtons(0); $searchpicto = $form->showFilterAndCheckAddButtons(0);
print $searchpicto; print $searchpicto;
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -586,8 +586,8 @@ print_liste_field_titre('StockToBuy', $_SERVER["PHP_SELF"], '', $param, '', '',
print_liste_field_titre('SupplierRef', $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right '); print_liste_field_titre('SupplierRef', $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right ');
// Hook fields // Hook fields
$parameters=array('param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder); $parameters = array('param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
$reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
print "</tr>\n"; print "</tr>\n";
@ -596,18 +596,18 @@ while ($i < ($limit ? min($num, $limit) : $num))
{ {
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
if (! empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0) if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0)
{ {
$prod->fetch($objp->rowid); $prod->fetch($objp->rowid);
$prod->load_stock('warehouseopen, warehouseinternal'); $prod->load_stock('warehouseopen, warehouseinternal');
// Multilangs // Multilangs
if (! empty($conf->global->MAIN_MULTILANGS)) if (!empty($conf->global->MAIN_MULTILANGS))
{ {
$sql = 'SELECT label,description'; $sql = 'SELECT label,description';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product_lang'; $sql .= ' FROM '.MAIN_DB_PREFIX.'product_lang';
$sql .= ' WHERE fk_product = ' . $objp->rowid; $sql .= ' WHERE fk_product = '.$objp->rowid;
$sql .= ' AND lang = "' . $langs->getDefaultLang() . '"'; $sql .= ' AND lang = "'.$langs->getDefaultLang().'"';
$sql .= ' LIMIT 1'; $sql .= ' LIMIT 1';
$resqlm = $db->query($sql); $resqlm = $db->query($sql);
@ -630,25 +630,25 @@ while ($i < ($limit ? min($num, $limit) : $num))
} }
// Force call prod->load_stats_xxx to choose status to count (otherwise it is loaded by load_stock function) // Force call prod->load_stats_xxx to choose status to count (otherwise it is loaded by load_stock function)
if(isset($draftchecked)){ if (isset($draftchecked)) {
$result=$prod->load_stats_commande_fournisseur(0, '0,1,2,3,4'); $result = $prod->load_stats_commande_fournisseur(0, '0,1,2,3,4');
}else { } else {
$result=$prod->load_stats_commande_fournisseur(0, '1,2,3,4'); $result = $prod->load_stats_commande_fournisseur(0, '1,2,3,4');
} }
$result=$prod->load_stats_reception(0, '4'); $result = $prod->load_stats_reception(0, '4');
//print $prod->stats_commande_fournisseur['qty'].'<br>'."\n"; //print $prod->stats_commande_fournisseur['qty'].'<br>'."\n";
//print $prod->stats_reception['qty']; //print $prod->stats_reception['qty'];
$ordered = $prod->stats_commande_fournisseur['qty'] - $prod->stats_reception['qty']; $ordered = $prod->stats_commande_fournisseur['qty'] - $prod->stats_reception['qty'];
$desiredstock=($objp->desiredstockpse ? $objp->desiredstockpse : $objp->desiredstock); $desiredstock = ($objp->desiredstockpse ? $objp->desiredstockpse : $objp->desiredstock);
$alertstock=($objp->seuil_stock_alertepse ? $objp->seuil_stock_alertepse : $objp->seuil_stock_alerte); $alertstock = ($objp->seuil_stock_alertepse ? $objp->seuil_stock_alertepse : $objp->seuil_stock_alerte);
$warning=''; $warning = '';
if ($alertstock && ($stock < $alertstock)) if ($alertstock && ($stock < $alertstock))
{ {
$warning = img_warning($langs->trans('StockTooLow')) . ' '; $warning = img_warning($langs->trans('StockTooLow')).' ';
} }
//depending on conf, use either physical stock or //depending on conf, use either physical stock or
@ -679,18 +679,18 @@ while ($i < ($limit ? min($num, $limit) : $num))
print '<td class="nowrap">'.$prod->getNomUrl(1, '').'</td>'; print '<td class="nowrap">'.$prod->getNomUrl(1, '').'</td>';
print '<td>'.$objp->label ; print '<td>'.$objp->label;
print '<input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp->description) . '">'; // TODO Remove this and make a fetch to get description when creating order instead of a GETPOST print '<input type="hidden" name="desc'.$i.'" value="'.dol_escape_htmltag($objp->description).'">'; // TODO Remove this and make a fetch to get description when creating order instead of a GETPOST
print '</td>'; print '</td>';
if (!empty($conf->service->enabled) && $type == 1) if (!empty($conf->service->enabled) && $type == 1)
{ {
if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
$duration = $regs[1] . ' ' . $langs->trans('DurationYear'); $duration = $regs[1].' '.$langs->trans('DurationYear');
} elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
$duration = $regs[1] . ' ' . $langs->trans('DurationMonth'); $duration = $regs[1].' '.$langs->trans('DurationMonth');
} elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
$duration = $regs[1] . ' ' . $langs->trans('DurationDay'); $duration = $regs[1].' '.$langs->trans('DurationDay');
} else { } else {
$duration = $objp->duration; $duration = $objp->duration;
} }
@ -698,27 +698,27 @@ while ($i < ($limit ? min($num, $limit) : $num))
} }
// Desired stock // Desired stock
print '<td class="right">' . $desiredstock . '</td>'; print '<td class="right">'.$desiredstock.'</td>';
// Limit stock for alert // Limit stock for alert
print '<td class="right">' . $alertstock . '</td>'; print '<td class="right">'.$alertstock.'</td>';
// Current stock (all warehouses) // Current stock (all warehouses)
print '<td class="right">'. $warning . $stock. '</td>'; print '<td class="right">'.$warning.$stock.'</td>';
// Already ordered // Already ordered
print '<td class="right"><a href="replenishorders.php?sproduct=' . $prod->id . '">'. $ordered . '</a> ' . $picto. '</td>'; print '<td class="right"><a href="replenishorders.php?sproduct='.$prod->id.'">'.$ordered.'</a> '.$picto.'</td>';
// To order // To order
//print '<td class="right"><input type="text" name="tobuy'.$i.'" value="'.$stocktobuy.'" '.$disabled.'></td>'; //print '<td class="right"><input type="text" name="tobuy'.$i.'" value="'.$stocktobuy.'" '.$disabled.'></td>';
print '<td class="right"><input type="text" size="4" name="tobuy'.$i.'" value="'.$stocktobuy.'"></td>'; print '<td class="right"><input type="text" size="4" name="tobuy'.$i.'" value="'.$stocktobuy.'"></td>';
// Supplier // Supplier
print '<td class="right">'. $form->select_product_fourn_price($prod->id, 'fourn'.$i, $fk_supplier).'</td>'; print '<td class="right">'.$form->select_product_fourn_price($prod->id, 'fourn'.$i, $fk_supplier).'</td>';
// Fields from hook // Fields from hook
$parameters=array( 'objp'=>$objp); $parameters = array('objp'=>$objp);
$reshook=$hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
print '</tr>'; print '</tr>';
@ -726,8 +726,8 @@ while ($i < ($limit ? min($num, $limit) : $num))
$i++; $i++;
} }
$parameters=array('sql'=>$sql); $parameters = array('sql'=>$sql);
$reshook=$hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
print '</table>'; print '</table>';
@ -738,7 +738,7 @@ $db->free($resql);
dol_fiche_end(); dol_fiche_end();
$value=$langs->trans("CreateOrders"); $value = $langs->trans("CreateOrders");
print '<div class="center"><input class="button" type="submit" name="valid" value="'.$value.'"></div>'; print '<div class="center"><input class="button" type="submit" name="valid" value="'.$value.'"></div>';

View File

@ -36,45 +36,45 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
$langs->loadLangs(array("sendings", "receptions", "deliveries", 'companies', 'bills')); $langs->loadLangs(array("sendings", "receptions", "deliveries", 'companies', 'bills'));
$socid=GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
$massaction=GETPOST('massaction', 'alpha'); $massaction = GETPOST('massaction', 'alpha');
$toselect = GETPOST('toselect', 'array'); $toselect = GETPOST('toselect', 'array');
// Security check // Security check
$receptionid = GETPOST('id', 'int'); $receptionid = GETPOST('id', 'int');
if ($user->socid) $socid=$user->socid; if ($user->socid) $socid = $user->socid;
$result = restrictedArea($user, 'reception', $receptionid, ''); $result = restrictedArea($user, 'reception', $receptionid, '');
$diroutputmassaction=$conf->reception->dir_output . '/temp/massgeneration/'.$user->id; $diroutputmassaction = $conf->reception->dir_output.'/temp/massgeneration/'.$user->id;
$search_ref_rcp = GETPOST("search_ref_rcp"); $search_ref_rcp = GETPOST("search_ref_rcp");
$search_ref_liv = GETPOST('search_ref_liv'); $search_ref_liv = GETPOST('search_ref_liv');
$search_ref_supplier = GETPOST('search_ref_supplier'); $search_ref_supplier = GETPOST('search_ref_supplier');
$search_company = GETPOST("search_company"); $search_company = GETPOST("search_company");
$search_town=GETPOST('search_town', 'alpha'); $search_town = GETPOST('search_town', 'alpha');
$search_zip=GETPOST('search_zip', 'alpha'); $search_zip = GETPOST('search_zip', 'alpha');
$search_state=trim(GETPOST("search_state")); $search_state = trim(GETPOST("search_state"));
$search_country=GETPOST("search_country", 'int'); $search_country = GETPOST("search_country", 'int');
$search_type_thirdparty=GETPOST("search_type_thirdparty", 'int'); $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
$search_billed=GETPOST("search_billed", 'int'); $search_billed = GETPOST("search_billed", 'int');
$sall = GETPOST('sall', 'alphanohtml'); $sall = GETPOST('sall', 'alphanohtml');
$optioncss = GETPOST('optioncss', 'alpha'); $optioncss = GETPOST('optioncss', 'alpha');
$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'alpha'); $sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOST('page', 'int'); $page = GETPOST('page', 'int');
if (! $sortfield) $sortfield="e.ref"; if (!$sortfield) $sortfield = "e.ref";
if (! $sortorder) $sortorder="DESC"; if (!$sortorder) $sortorder = "DESC";
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; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$contextpage='receptionlist'; $contextpage = 'receptionlist';
$viewstatut=GETPOST('viewstatut'); $viewstatut = GETPOST('viewstatut');
$object = new Reception($db); $object = new Reception($db);
@ -92,10 +92,10 @@ $fieldstosearchall = array(
's.nom'=>"ThirdParty", 's.nom'=>"ThirdParty",
'e.note_public'=>'NotePublic', 'e.note_public'=>'NotePublic',
); );
if (empty($user->socid)) $fieldstosearchall["e.note_private"]="NotePrivate"; if (empty($user->socid)) $fieldstosearchall["e.note_private"] = "NotePrivate";
$checkedtypetiers=0; $checkedtypetiers = 0;
$arrayfields=array( $arrayfields = array(
'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), 'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
'e.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1), 'e.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1), 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
@ -113,10 +113,10 @@ $arrayfields=array(
// Extra fields // Extra fields
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0)
{ {
foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val) foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val)
{ {
if (! empty($extrafields->attributes[$object->table_element]['list'][$key])) if (!empty($extrafields->attributes[$object->table_element]['list'][$key]))
$arrayfields["ef.".$key]=array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key]<0)?0:1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key])!=3 && $extrafields->attributes[$object->table_element]['perms'][$key])); $arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key]));
} }
} }
$object->fields = dol_sort_array($object->fields, 'position'); $object->fields = dol_sort_array($object->fields, 'position');
@ -127,11 +127,11 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
* Actions * Actions
*/ */
if (GETPOST('cancel')) { $action='list'; $massaction=''; } if (GETPOST('cancel')) { $action = 'list'; $massaction = ''; }
if (! GETPOST('confirmmassaction') && $massaction != 'confirm_createbills') { $massaction=''; } if (!GETPOST('confirmmassaction') && $massaction != 'confirm_createbills') { $massaction = ''; }
$parameters=array('socid'=>$socid); $parameters = array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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');
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
@ -139,18 +139,18 @@ include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria // Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
{ {
$search_ref_supplier=''; $search_ref_supplier = '';
$search_ref_rcp=''; $search_ref_rcp = '';
$search_ref_liv=''; $search_ref_liv = '';
$search_company=''; $search_company = '';
$search_town=''; $search_town = '';
$search_zip=""; $search_zip = "";
$search_state=""; $search_state = "";
$search_country=''; $search_country = '';
$search_type_thirdparty=''; $search_type_thirdparty = '';
$search_billed=''; $search_billed = '';
$viewstatut=''; $viewstatut = '';
$search_array_options=array(); $search_array_options = array();
} }
if (empty($reshook)) if (empty($reshook))
@ -166,29 +166,29 @@ if (empty($reshook))
$nb_bills_created = 0; $nb_bills_created = 0;
$db->begin(); $db->begin();
$errors =array(); $errors = array();
foreach($receptions as $id_reception) foreach ($receptions as $id_reception)
{ {
$rcp = new Reception($db); $rcp = new Reception($db);
// On ne facture que les réceptions validées // On ne facture que les réceptions validées
if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != 1){ if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != 1) {
$errors[]=$langs->trans('StatusMustBeValidate', $rcp->ref); $errors[] = $langs->trans('StatusMustBeValidate', $rcp->ref);
$error++; $error++;
continue; continue;
} }
$object = new FactureFournisseur($db); $object = new FactureFournisseur($db);
if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])){ if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) {
$object = $TFactThird[$rcp->socid]; // If option "one bill per third" is set, we use already created reception. $object = $TFactThird[$rcp->socid]; // If option "one bill per third" is set, we use already created reception.
if(empty($object->rowid)&&$object->id != null)$object->rowid = $object->id; if (empty($object->rowid) && $object->id != null)$object->rowid = $object->id;
if(!empty($object->rowid))$object->fetchObjectLinked(); if (!empty($object->rowid))$object->fetchObjectLinked();
$rcp->fetchObjectLinked(); $rcp->fetchObjectLinked();
if (count($rcp->linkedObjectsIds['order_supplier']) > 0) if (count($rcp->linkedObjectsIds['order_supplier']) > 0)
{ {
foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value) foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value)
{ {
if(empty($object->linkedObjectsIds['order_supplier']) || !in_array($value, $object->linkedObjectsIds['order_supplier']))//Dont try to link if already linked if (empty($object->linkedObjectsIds['order_supplier']) || !in_array($value, $object->linkedObjectsIds['order_supplier']))//Dont try to link if already linked
$object->add_object_linked('order_supplier', $value); // add supplier order linked object $object->add_object_linked('order_supplier', $value); // add supplier order linked object
} }
} }
@ -198,12 +198,12 @@ if (empty($reshook))
$object->type = FactureFournisseur::TYPE_STANDARD; $object->type = FactureFournisseur::TYPE_STANDARD;
$object->cond_reglement_id = $rcp->thirdparty->cond_reglement_supplier_id; $object->cond_reglement_id = $rcp->thirdparty->cond_reglement_supplier_id;
$object->mode_reglement_id = $rcp->thirdparty->mode_reglement_supplier_id; $object->mode_reglement_id = $rcp->thirdparty->mode_reglement_supplier_id;
$object->fk_account = !empty($rcp->thirdparty->fk_account)?$rcp->thirdparty->fk_account:0; $object->fk_account = !empty($rcp->thirdparty->fk_account) ? $rcp->thirdparty->fk_account : 0;
$object->remise_percent = !empty($rcp->thirdparty->remise_percent)?$rcp->thirdparty->remise_percent:0; $object->remise_percent = !empty($rcp->thirdparty->remise_percent) ? $rcp->thirdparty->remise_percent : 0;
$object->remise_absolue = !empty($rcp->thirdparty->remise_absolue)?$rcp->thirdparty->remise_absolue:0; $object->remise_absolue = !empty($rcp->thirdparty->remise_absolue) ? $rcp->thirdparty->remise_absolue : 0;
$object->fk_project = $rcp->fk_project; $object->fk_project = $rcp->fk_project;
$object->ref_supplier = $rcp->ref_supplier; $object->ref_supplier = $rcp->ref_supplier;
$datefacture = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
if (empty($datefacture)) if (empty($datefacture))
@ -226,28 +226,28 @@ if (empty($reshook))
$res = $object->create($user); $res = $object->create($user);
//var_dump($object->error);exit; //var_dump($object->error);exit;
if($res > 0){ if ($res > 0) {
$nb_bills_created++; $nb_bills_created++;
$object->id = $res; $object->id = $res;
}else { } else {
$errors[]=$rcp->ref.' : '.$langs->trans($object->error); $errors[] = $rcp->ref.' : '.$langs->trans($object->error);
$error++; $error++;
} }
} }
if ($object->id > 0) if ($object->id > 0)
{ {
if(!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])){ //cause function create already add object linked for facturefournisseur if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) { //cause function create already add object linked for facturefournisseur
$res = $object->add_object_linked($object->origin, $id_reception); $res = $object->add_object_linked($object->origin, $id_reception);
if ($res==0) if ($res == 0)
{ {
$errors[]=$object->error; $errors[] = $object->error;
$error++; $error++;
} }
} }
if (! $error) if (!$error)
{ {
$lines = $rcp->lines; $lines = $rcp->lines;
if (empty($lines) && method_exists($rcp, 'fetch_lines')) if (empty($lines) && method_exists($rcp, 'fetch_lines'))
@ -256,27 +256,27 @@ if (empty($reshook))
$lines = $rcp->lines; $lines = $rcp->lines;
} }
$fk_parent_line=0; $fk_parent_line = 0;
$num=count($lines); $num = count($lines);
for ($i=0;$i<$num;$i++) for ($i = 0; $i < $num; $i++)
{ {
$desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
if ($lines[$i]->subprice < 0) if ($lines[$i]->subprice < 0)
{ {
// Negative line, we create a discount line // Negative line, we create a discount line
$discount = new DiscountAbsolute($db); $discount = new DiscountAbsolute($db);
$discount->fk_soc=$object->socid; $discount->fk_soc = $object->socid;
$discount->amount_ht=abs($lines[$i]->total_ht); $discount->amount_ht = abs($lines[$i]->total_ht);
$discount->amount_tva=abs($lines[$i]->total_tva); $discount->amount_tva = abs($lines[$i]->total_tva);
$discount->amount_ttc=abs($lines[$i]->total_ttc); $discount->amount_ttc = abs($lines[$i]->total_ttc);
$discount->tva_tx=$lines[$i]->tva_tx; $discount->tva_tx = $lines[$i]->tva_tx;
$discount->fk_user=$user->id; $discount->fk_user = $user->id;
$discount->description=$desc; $discount->description = $desc;
$discountid=$discount->create($user); $discountid = $discount->create($user);
if ($discountid > 0) if ($discountid > 0)
{ {
$result=$object->insert_discount($discountid); $result = $object->insert_discount($discountid);
//$result=$discount->link_to_invoice($lineid,$id); //$result=$discount->link_to_invoice($lineid,$id);
} }
else else
@ -289,17 +289,17 @@ if (empty($reshook))
else else
{ {
// Positive line // Positive line
$product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
// Date start // Date start
$date_start=false; $date_start = false;
if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue; if ($lines[$i]->date_debut_prevue) $date_start = $lines[$i]->date_debut_prevue;
if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; if ($lines[$i]->date_debut_reel) $date_start = $lines[$i]->date_debut_reel;
if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; if ($lines[$i]->date_start) $date_start = $lines[$i]->date_start;
//Date end //Date end
$date_end=false; $date_end = false;
if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue; if ($lines[$i]->date_fin_prevue) $date_end = $lines[$i]->date_fin_prevue;
if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; if ($lines[$i]->date_fin_reel) $date_end = $lines[$i]->date_fin_reel;
if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; if ($lines[$i]->date_end) $date_end = $lines[$i]->date_end;
// Reset fk_parent_line for no child products and special product // Reset fk_parent_line for no child products and special product
if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
{ {
@ -333,11 +333,11 @@ if (empty($reshook))
if ($result > 0) if ($result > 0)
{ {
$lineid=$result; $lineid = $result;
} }
else else
{ {
$lineid=0; $lineid = 0;
$error++; $error++;
break; break;
} }
@ -353,7 +353,7 @@ if (empty($reshook))
//$rcp->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module. //$rcp->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module.
if(!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) $TFactThird[$rcp->socid] = $object; if (!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) $TFactThird[$rcp->socid] = $object;
else $TFact[$object->id] = $object; else $TFact[$object->id] = $object;
} }
@ -361,10 +361,10 @@ if (empty($reshook))
$TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird; $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
$toselect = array(); $toselect = array();
if (! $error && $validate_invoices) if (!$error && $validate_invoices)
{ {
$massaction = $action = 'builddoc'; $massaction = $action = 'builddoc';
foreach($TAllFact as &$object) foreach ($TAllFact as &$object)
{ {
$result = $object->validate($user); $result = $object->validate($user);
if ($result <= 0) if ($result <= 0)
@ -379,14 +379,14 @@ if (empty($reshook))
// Fac builddoc // Fac builddoc
$donotredirect = 1; $donotredirect = 1;
$upload_dir = $conf->fournisseur->facture->dir_output; $upload_dir = $conf->fournisseur->facture->dir_output;
$permissiontoadd=$user->rights->fournisseur->facture->creer; $permissiontoadd = $user->rights->fournisseur->facture->creer;
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
} }
$massaction = $action = 'confirm_createbills'; $massaction = $action = 'confirm_createbills';
} }
if (! $error) if (!$error)
{ {
$db->commit(); $db->commit();
setEventMessage($langs->trans('BillCreated', $nb_bills_created)); setEventMessage($langs->trans('BillCreated', $nb_bills_created));
@ -394,9 +394,9 @@ if (empty($reshook))
else else
{ {
$db->rollback(); $db->rollback();
$action='create'; $action = 'create';
$_GET["origin"]=$_POST["origin"]; $_GET["origin"] = $_POST["origin"];
$_GET["originid"]=$_POST["originid"]; $_GET["originid"] = $_POST["originid"];
setEventMessages($object->error, $errors, 'errors'); setEventMessages($object->error, $errors, 'errors');
$error++; $error++;
} }
@ -408,58 +408,58 @@ if (empty($reshook))
* View * View
*/ */
$form=new Form($db); $form = new Form($db);
$companystatic=new Societe($db); $companystatic = new Societe($db);
$reception=new Reception($db); $reception = new Reception($db);
$formcompany=new FormCompany($db); $formcompany = new FormCompany($db);
$formfile = new FormFile($db); $formfile = new FormFile($db);
$helpurl='EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones'; $helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
llxHeader('', $langs->trans('ListOfReceptions'), $helpurl); llxHeader('', $langs->trans('ListOfReceptions'), $helpurl);
$sql = "SELECT e.rowid, e.ref, e.ref_supplier, e.date_reception as date_reception, e.date_delivery as date_livraison, l.date_delivery as date_reception, e.fk_statut, e.billed,"; $sql = "SELECT e.rowid, e.ref, e.ref_supplier, e.date_reception as date_reception, e.date_delivery as date_livraison, l.date_delivery as date_reception, e.fk_statut, e.billed,";
$sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, '; $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
$sql.= " typent.code as typent_code,"; $sql .= " typent.code as typent_code,";
$sql.= " state.code_departement as state_code, state.nom as state_name,"; $sql .= " state.code_departement as state_code, state.nom as state_name,";
$sql.= ' e.date_creation as date_creation, e.tms as date_update'; $sql .= ' e.date_creation as date_creation, e.tms as date_update';
// Add fields from extrafields // Add fields from extrafields
if (! empty($extrafields->attributes[$object->table_element]['label'])) { if (!empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
} }
// Add fields from hooks // Add fields from hooks
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint; $sql .= $hookmanager->resPrint;
$sql.= " FROM ".MAIN_DB_PREFIX."reception as e"; $sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)"; if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'reception' AND ee.targettype = 'delivery'"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'reception' AND ee.targettype = 'delivery'";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target";
if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all
{ {
$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
} }
$sql.= " WHERE e.entity IN (".getEntity('reception').")"; $sql .= " WHERE e.entity IN (".getEntity('reception').")";
if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all
{ {
$sql.= " AND e.fk_soc = sc.fk_soc"; $sql .= " AND e.fk_soc = sc.fk_soc";
$sql.= " AND sc.fk_user = " .$user->id; $sql .= " AND sc.fk_user = ".$user->id;
} }
if ($socid) if ($socid)
{ {
$sql.= " AND e.fk_soc = ".$socid; $sql .= " AND e.fk_soc = ".$socid;
} }
if ($viewstatut <> '' && $viewstatut >= 0) { if ($viewstatut <> '' && $viewstatut >= 0) {
$sql.= " AND e.fk_statut = ".$viewstatut; $sql .= " AND e.fk_statut = ".$viewstatut;
} }
if ($search_billed != '' && $search_billed >= 0) $sql.=' AND e.billed = '.$search_billed; if ($search_billed != '' && $search_billed >= 0) $sql .= ' AND e.billed = '.$search_billed;
if ($search_town) $sql.= natural_search('s.town', $search_town); if ($search_town) $sql .= natural_search('s.town', $search_town);
if ($search_zip) $sql.= natural_search("s.zip", $search_zip); if ($search_zip) $sql .= natural_search("s.zip", $search_zip);
if ($search_state) $sql.= natural_search("state.nom", $search_state); if ($search_state) $sql .= natural_search("state.nom", $search_state);
if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')'; if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')'; if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
if ($search_ref_rcp) $sql .= natural_search('e.ref', $search_ref_rcp); if ($search_ref_rcp) $sql .= natural_search('e.ref', $search_ref_rcp);
@ -471,21 +471,21 @@ if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
// Add where from extra fields // Add where from extra fields
foreach ($search_array_options as $key => $val) foreach ($search_array_options as $key => $val)
{ {
$crit=$val; $crit = $val;
$tmpkey=preg_replace('/search_options_/', '', $key); $tmpkey = preg_replace('/search_options_/', '', $key);
$typ=$extrafields->attributes[$object->table_element]['type'][$tmpkey]; $typ = $extrafields->attributes[$object->table_element]['type'][$tmpkey];
$mode=0; $mode = 0;
if (in_array($typ, array('int','double','real'))) $mode=1; // Search on a numeric if (in_array($typ, array('int', 'double', 'real'))) $mode = 1; // Search on a numeric
if (in_array($typ, array('sellist')) && $crit != '0' && $crit != '-1') $mode=2; // Search on a foreign key int if (in_array($typ, array('sellist')) && $crit != '0' && $crit != '-1') $mode = 2; // Search on a foreign key int
if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0')) if ($crit != '' && (!in_array($typ, array('select', 'sellist')) || $crit != '0'))
{ {
$sql .= natural_search('ef.'.$tmpkey, $crit, $mode); $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
} }
} }
// Add where from hooks // Add where from hooks
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint; $sql .= $hookmanager->resPrint;
$nbtotalofrecords = ''; $nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
@ -494,51 +494,51 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$nbtotalofrecords = $db->num_rows($result); $nbtotalofrecords = $db->num_rows($result);
} }
$sql.= $db->order($sortfield, $sortorder); $sql .= $db->order($sortfield, $sortorder);
$sql.= $db->plimit($limit + 1, $offset); $sql .= $db->plimit($limit + 1, $offset);
//print $sql; //print $sql;
$resql=$db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$reception = new Reception($db); $reception = new Reception($db);
$arrayofselected=is_array($toselect)?$toselect:array(); $arrayofselected = is_array($toselect) ? $toselect : array();
$param=''; $param = '';
if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
if ($sall) $param.= "&amp;sall=".$sall; if ($sall) $param .= "&amp;sall=".$sall;
if ($search_ref_rcp) $param.= "&amp;search_ref_rcp=".$search_ref_rcp; if ($search_ref_rcp) $param .= "&amp;search_ref_rcp=".$search_ref_rcp;
if ($search_ref_liv) $param.= "&amp;search_ref_liv=".$search_ref_liv; if ($search_ref_liv) $param .= "&amp;search_ref_liv=".$search_ref_liv;
if ($search_company) $param.= "&amp;search_company=".$search_company; if ($search_company) $param .= "&amp;search_company=".$search_company;
if ($optioncss != '') $param.='&amp;optioncss='.$optioncss; if ($optioncss != '') $param .= '&amp;optioncss='.$optioncss;
if ($search_billed != '' && $search_billed >= 0)$param.= "&amp;search_billed=".$search_billed; if ($search_billed != '' && $search_billed >= 0)$param .= "&amp;search_billed=".$search_billed;
if ($search_town) $param.= "&amp;search_town=".$search_town; if ($search_town) $param .= "&amp;search_town=".$search_town;
if ($search_zip) $param.= "&amp;search_zip=".$search_zip; if ($search_zip) $param .= "&amp;search_zip=".$search_zip;
if ($search_state) $param.= "&amp;search_state=".$search_state; if ($search_state) $param .= "&amp;search_state=".$search_state;
if ($viewstatut) $param.= "&amp;viewstatut=".$viewstatut; if ($viewstatut) $param .= "&amp;viewstatut=".$viewstatut;
if ($search_country) $param.= "&amp;search_country=".$search_country; if ($search_country) $param .= "&amp;search_country=".$search_country;
if ($search_type_thirdparty) $param.= "&amp;search_type_thirdparty=".$search_type_thirdparty; if ($search_type_thirdparty) $param .= "&amp;search_type_thirdparty=".$search_type_thirdparty;
if ($search_ref_supplier) $param.= "&amp;search_ref_supplier=".$search_ref_supplier; if ($search_ref_supplier) $param .= "&amp;search_ref_supplier=".$search_ref_supplier;
// Add $param from extra fields // Add $param from extra fields
foreach ($search_array_options as $key => $val) foreach ($search_array_options as $key => $val)
{ {
$crit=$val; $crit = $val;
$tmpkey=preg_replace('/search_options_/', '', $key); $tmpkey = preg_replace('/search_options_/', '', $key);
if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); if ($val != '') $param .= '&search_options_'.$tmpkey.'='.urlencode($val);
} }
$arrayofmassactions = array( $arrayofmassactions = array(
// 'presend'=>$langs->trans("SendByMail"), // 'presend'=>$langs->trans("SendByMail"),
); );
if($user->rights->fournisseur->facture->creer)$arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisSupplier"); if ($user->rights->fournisseur->facture->creer)$arrayofmassactions['createbills'] = $langs->trans("CreateInvoiceForThisSupplier");
if($massaction == 'createbills') $arrayofmassactions=array(); if ($massaction == 'createbills') $arrayofmassactions = array();
$massactionbutton=$form->selectMassAction('', $arrayofmassactions); $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
//$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"))); //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
$i = 0; $i = 0;
@ -581,7 +581,7 @@ if ($resql)
print $langs->trans('ValidateInvoices'); print $langs->trans('ValidateInvoices');
print '</td>'; print '</td>';
print '<td>'; print '<td>';
if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL)) if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL))
{ {
print $form->selectyesno('validate_invoices', 0, 1, 1); print $form->selectyesno('validate_invoices', 0, 1, 1);
print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')'; print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
@ -604,91 +604,91 @@ if ($resql)
if ($sall) if ($sall)
{ {
foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
print $langs->trans("FilterOnInto", $sall) . join(', ', $fieldstosearchall); print $langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall);
} }
$moreforfilter=''; $moreforfilter = '';
if (! empty($moreforfilter)) if (!empty($moreforfilter))
{ {
print '<div class="liste_titre liste_titre_bydiv centpercent">'; print '<div class="liste_titre liste_titre_bydiv centpercent">';
print $moreforfilter; print $moreforfilter;
$parameters=array('type'=>$type); $parameters = array('type'=>$type);
$reshook=$hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
print '</div>'; print '</div>';
} }
$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
$selectedfields.=$form->showCheckAddButtons('checkforselect', 1); $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
print '<div class="div-table-responsive">'; print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n"; print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
// Fields title search // Fields title search
// -------------------------------------------------------------------- // --------------------------------------------------------------------
print '<tr class="liste_titre_filter">'; print '<tr class="liste_titre_filter">';
// Ref // Ref
if (! empty($arrayfields['e.ref']['checked'])) if (!empty($arrayfields['e.ref']['checked']))
{ {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '<input class="flat" size="6" type="text" name="search_ref_rcp" value="'.$search_ref_rcp.'">'; print '<input class="flat" size="6" type="text" name="search_ref_rcp" value="'.$search_ref_rcp.'">';
print '</td>'; print '</td>';
} }
// Ref customer // Ref customer
if (! empty($arrayfields['e.ref_supplier']['checked'])) if (!empty($arrayfields['e.ref_supplier']['checked']))
{ {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '<input class="flat" size="6" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'">'; print '<input class="flat" size="6" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'">';
print '</td>'; print '</td>';
} }
// Thirdparty // Thirdparty
if (! empty($arrayfields['s.nom']['checked'])) if (!empty($arrayfields['s.nom']['checked']))
{ {
print '<td class="liste_titre left">'; print '<td class="liste_titre left">';
print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">'; print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
print '</td>'; print '</td>';
} }
// Town // Town
if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>'; if (!empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
// Zip // Zip
if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>'; if (!empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
// State // State
if (! empty($arrayfields['state.nom']['checked'])) if (!empty($arrayfields['state.nom']['checked']))
{ {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">'; print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
print '</td>'; print '</td>';
} }
// Country // Country
if (! empty($arrayfields['country.code_iso']['checked'])) if (!empty($arrayfields['country.code_iso']['checked']))
{ {
print '<td class="liste_titre center">'; print '<td class="liste_titre center">';
print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100'); print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
print '</td>'; print '</td>';
} }
// Company type // Company type
if (! empty($arrayfields['typent.code']['checked'])) if (!empty($arrayfields['typent.code']['checked']))
{ {
print '<td class="liste_titre maxwidthonsmartphone center">'; print '<td class="liste_titre maxwidthonsmartphone center">';
print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT)); print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));
print '</td>'; print '</td>';
} }
// Date delivery planned // Date delivery planned
if (! empty($arrayfields['e.date_delivery']['checked'])) if (!empty($arrayfields['e.date_delivery']['checked']))
{ {
print '<td class="liste_titre">&nbsp;</td>'; print '<td class="liste_titre">&nbsp;</td>';
} }
if (! empty($arrayfields['l.ref']['checked'])) if (!empty($arrayfields['l.ref']['checked']))
{ {
// Delivery ref // Delivery ref
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"'; print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
print '</td>'; print '</td>';
} }
if (! empty($arrayfields['l.date_delivery']['checked'])) if (!empty($arrayfields['l.date_delivery']['checked']))
{ {
// Date received // Date received
print '<td class="liste_titre">&nbsp;</td>'; print '<td class="liste_titre">&nbsp;</td>';
@ -697,30 +697,30 @@ if ($resql)
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
// Fields from hook // Fields from hook
$parameters=array('arrayfields'=>$arrayfields); $parameters = array('arrayfields'=>$arrayfields);
$reshook=$hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
// Date creation // Date creation
if (! empty($arrayfields['e.datec']['checked'])) if (!empty($arrayfields['e.datec']['checked']))
{ {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '</td>'; print '</td>';
} }
// Date modification // Date modification
if (! empty($arrayfields['e.tms']['checked'])) if (!empty($arrayfields['e.tms']['checked']))
{ {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '</td>'; print '</td>';
} }
// Status // Status
if (! empty($arrayfields['e.fk_statut']['checked'])) if (!empty($arrayfields['e.fk_statut']['checked']))
{ {
print '<td class="liste_titre maxwidthonsmartphone right">'; print '<td class="liste_titre maxwidthonsmartphone right">';
print $form->selectarray('viewstatut', array('0'=>$langs->trans('StatusReceptionDraftShort'),'1'=>$langs->trans('StatusReceptionValidatedShort'),'2'=>$langs->trans('StatusReceptionProcessedShort')), $viewstatut, 1); print $form->selectarray('viewstatut', array('0'=>$langs->trans('StatusReceptionDraftShort'), '1'=>$langs->trans('StatusReceptionValidatedShort'), '2'=>$langs->trans('StatusReceptionProcessedShort')), $viewstatut, 1);
print '</td>'; print '</td>';
} }
// Status billed // Status billed
if (! empty($arrayfields['e.billed']['checked'])) if (!empty($arrayfields['e.billed']['checked']))
{ {
print '<td class="liste_titre maxwidthonsmartphone center">'; print '<td class="liste_titre maxwidthonsmartphone center">';
print $form->selectyesno('search_billed', $search_billed, 1, 0, 1); print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
@ -728,126 +728,126 @@ if ($resql)
} }
// Action column // Action column
print '<td class="liste_titre middle">'; print '<td class="liste_titre middle">';
$searchpicto=$form->showFilterAndCheckAddButtons(0); $searchpicto = $form->showFilterAndCheckAddButtons(0);
print $searchpicto; print $searchpicto;
print '</td>'; print '</td>';
print "</tr>\n"; print "</tr>\n";
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
if (! empty($arrayfields['e.ref']['checked'])) print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['e.ref']['checked'])) print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
if (! empty($arrayfields['e.ref_supplier']['checked'])) print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"], "e.ref_supplier", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['e.ref_supplier']['checked'])) print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"], "e.ref_supplier", "", $param, '', $sortfield, $sortorder);
if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left '); if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');
if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder); if (!empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder); if (!empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
if (! empty($arrayfields['e.date_delivery']['checked'])) print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['e.date_delivery']['checked'])) print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
if (! empty($arrayfields['l.ref']['checked'])) print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['l.ref']['checked'])) print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
if (! empty($arrayfields['l.date_delivery']['checked'])) print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['l.date_delivery']['checked'])) print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
// Extra fields // Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields // Hook fields
$parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder); $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
$reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
if (! empty($arrayfields['e.datec']['checked'])) print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap '); if (!empty($arrayfields['e.datec']['checked'])) print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
if (! empty($arrayfields['e.tms']['checked'])) print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); if (!empty($arrayfields['e.tms']['checked'])) print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
if (! empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right '); if (!empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
if (! empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
print "</tr>\n"; print "</tr>\n";
$i=0; $i = 0;
$totalarray=array(); $totalarray = array();
while ($i < min($num, $limit)) while ($i < min($num, $limit))
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$reception->id=$obj->rowid; $reception->id = $obj->rowid;
$reception->ref=$obj->ref; $reception->ref = $obj->ref;
$companystatic->id=$obj->socid; $companystatic->id = $obj->socid;
$companystatic->ref=$obj->name; $companystatic->ref = $obj->name;
$companystatic->name=$obj->name; $companystatic->name = $obj->name;
print '<tr class="oddeven">'; print '<tr class="oddeven">';
// Ref // Ref
if (! empty($arrayfields['e.ref']['checked'])) if (!empty($arrayfields['e.ref']['checked']))
{ {
print "<td>"; print "<td>";
print $reception->getNomUrl(1); print $reception->getNomUrl(1);
$filename=dol_sanitizeFileName($reception->ref); $filename = dol_sanitizeFileName($reception->ref);
$filedir=$conf->reception->dir_output . '/' . dol_sanitizeFileName($reception->ref); $filedir = $conf->reception->dir_output.'/'.dol_sanitizeFileName($reception->ref);
$urlsource=$_SERVER['PHP_SELF'].'?id='.$reception->rowid; $urlsource = $_SERVER['PHP_SELF'].'?id='.$reception->rowid;
print $formfile->getDocumentsLink($reception->element, $filename, $filedir); print $formfile->getDocumentsLink($reception->element, $filename, $filedir);
print "</td>\n"; print "</td>\n";
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// Ref customer // Ref customer
if (! empty($arrayfields['e.ref_supplier']['checked'])) if (!empty($arrayfields['e.ref_supplier']['checked']))
{ {
print "<td>"; print "<td>";
print $obj->ref_supplier; print $obj->ref_supplier;
print "</td>\n"; print "</td>\n";
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// Third party // Third party
if (! empty($arrayfields['s.nom']['checked'])) if (!empty($arrayfields['s.nom']['checked']))
{ {
print '<td>'; print '<td>';
print $companystatic->getNomUrl(1); print $companystatic->getNomUrl(1);
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// Town // Town
if (! empty($arrayfields['s.town']['checked'])) if (!empty($arrayfields['s.town']['checked']))
{ {
print '<td class="nocellnopadd">'; print '<td class="nocellnopadd">';
print $obj->town; print $obj->town;
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// Zip // Zip
if (! empty($arrayfields['s.zip']['checked'])) if (!empty($arrayfields['s.zip']['checked']))
{ {
print '<td class="nocellnopadd">'; print '<td class="nocellnopadd">';
print $obj->zip; print $obj->zip;
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// State // State
if (! empty($arrayfields['state.nom']['checked'])) if (!empty($arrayfields['state.nom']['checked']))
{ {
print "<td>".$obj->state_name."</td>\n"; print "<td>".$obj->state_name."</td>\n";
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// Country // Country
if (! empty($arrayfields['country.code_iso']['checked'])) if (!empty($arrayfields['country.code_iso']['checked']))
{ {
print '<td class="center">'; print '<td class="center">';
$tmparray=getCountry($obj->fk_pays, 'all'); $tmparray = getCountry($obj->fk_pays, 'all');
print $tmparray['label']; print $tmparray['label'];
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// Type ent // Type ent
if (! empty($arrayfields['typent.code']['checked'])) if (!empty($arrayfields['typent.code']['checked']))
{ {
print '<td class="center">'; print '<td class="center">';
if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1); if (count($typenArray) == 0) $typenArray = $formcompany->typent_array(1);
print $typenArray[$obj->typent_code]; print $typenArray[$obj->typent_code];
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// Date delivery planed // Date delivery planed
if (! empty($arrayfields['e.date_delivery']['checked'])) if (!empty($arrayfields['e.date_delivery']['checked']))
{ {
print '<td class="center">'; print '<td class="center">';
print dol_print_date($db->jdate($obj->date_livraison), "day"); print dol_print_date($db->jdate($obj->date_livraison), "day");
@ -858,13 +858,13 @@ if ($resql)
print "</td>\n"; print "</td>\n";
} }
if (! empty($arrayfields['l.ref']['checked']) || ! empty($arrayfields['l.date_delivery']['checked'])) if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked']))
{ {
$reception->fetchObjectLinked($reception->id, $reception->element); $reception->fetchObjectLinked($reception->id, $reception->element);
$receiving=''; $receiving = '';
if (count($reception->linkedObjects['delivery']) > 0) $receiving=reset($reception->linkedObjects['delivery']); if (count($reception->linkedObjects['delivery']) > 0) $receiving = reset($reception->linkedObjects['delivery']);
if (! empty($arrayfields['l.ref']['checked'])) if (!empty($arrayfields['l.ref']['checked']))
{ {
// Ref // Ref
print '<td>'; print '<td>';
@ -872,7 +872,7 @@ if ($resql)
print '</td>'; print '</td>';
} }
if (! empty($arrayfields['l.date_delivery']['checked'])) if (!empty($arrayfields['l.date_delivery']['checked']))
{ {
// Date received // Date received
print '<td class="center">'; print '<td class="center">';
@ -885,48 +885,48 @@ if ($resql)
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
// Fields from hook // Fields from hook
$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj);
$reshook=$hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
// Date creation // Date creation
if (! empty($arrayfields['e.datec']['checked'])) if (!empty($arrayfields['e.datec']['checked']))
{ {
print '<td class="center nowrap">'; print '<td class="center nowrap">';
print dol_print_date($db->jdate($obj->date_creation), 'dayhour'); print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// Date modification // Date modification
if (! empty($arrayfields['e.tms']['checked'])) if (!empty($arrayfields['e.tms']['checked']))
{ {
print '<td class="center nowrap">'; print '<td class="center nowrap">';
print dol_print_date($db->jdate($obj->date_update), 'dayhour'); print dol_print_date($db->jdate($obj->date_update), 'dayhour');
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// Status // Status
if (! empty($arrayfields['e.fk_statut']['checked'])) if (!empty($arrayfields['e.fk_statut']['checked']))
{ {
print '<td class="right nowrap">'.$reception->LibStatut($obj->fk_statut, 5).'</td>'; print '<td class="right nowrap">'.$reception->LibStatut($obj->fk_statut, 5).'</td>';
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// Billed // Billed
if (! empty($arrayfields['e.billed']['checked'])) if (!empty($arrayfields['e.billed']['checked']))
{ {
print '<td class="center">'.yn($obj->billed).'</td>'; print '<td class="center">'.yn($obj->billed).'</td>';
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
} }
// Action column // Action column
print '<td class="center">'; print '<td class="center">';
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{ {
$selected=0; $selected = 0;
if (in_array($obj->rowid, $arrayofselected)) $selected=1; if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>'; print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
} }
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
print "</tr>\n"; print "</tr>\n";

View File

@ -40,7 +40,7 @@ $cancel = GETPOST('cancel', 'alpha');
$ref = GETPOST('ref', 'alpha'); $ref = GETPOST('ref', 'alpha');
$description = GETPOST('description'); $description = GETPOST('description');
$confirm = GETPOST('confirm'); $confirm = GETPOST('confirm');
$fk_code_type_resource = GETPOST('fk_code_type_resource', 'alpha'); $fk_code_type_resource = GETPOST('fk_code_type_resource', 'alpha');
$country_id = GETPOST('country_id', 'int'); $country_id = GETPOST('country_id', 'int');
// Protection if external user // Protection if external user
@ -49,7 +49,7 @@ if ($user->socid > 0)
accessforbidden(); accessforbidden();
} }
if( ! $user->rights->resource->read) if (!$user->rights->resource->read)
{ {
accessforbidden(); accessforbidden();
} }
@ -67,16 +67,16 @@ $extrafields->fetch_name_optionals_label($object->table_element);
* Actions * Actions
*/ */
$hookmanager->initHooks(array('resource', 'resource_card','globalcard')); $hookmanager->initHooks(array('resource', 'resource_card', 'globalcard'));
$parameters=array('resource_id'=>$id); $parameters = array('resource_id'=>$id);
$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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))
{ {
if ($cancel) if ($cancel)
{ {
if (! empty($backtopage)) if (!empty($backtopage))
{ {
header("Location: ".$backtopage); header("Location: ".$backtopage);
exit; exit;
@ -86,14 +86,14 @@ if (empty($reshook))
header("Location: ".DOL_URL_ROOT.'/resource/list.php'); header("Location: ".DOL_URL_ROOT.'/resource/list.php');
exit; exit;
} }
$action=''; $action = '';
} }
if ($action == 'add' && $user->rights->resource->write) if ($action == 'add' && $user->rights->resource->write)
{ {
if (! $cancel) if (!$cancel)
{ {
$error=''; $error = '';
if (empty($ref)) if (empty($ref))
{ {
@ -111,7 +111,7 @@ if (empty($reshook))
$ret = $extrafields->setOptionalsFromPost(null, $object); $ret = $extrafields->setOptionalsFromPost(null, $object);
if ($ret < 0) $error++; if ($ret < 0) $error++;
$result=$object->create($user); $result = $object->create($user);
if ($result > 0) if ($result > 0)
{ {
// Creation OK // Creation OK
@ -134,9 +134,9 @@ if (empty($reshook))
} }
} }
if ($action == 'update' && ! $cancel && $user->rights->resource->write) if ($action == 'update' && !$cancel && $user->rights->resource->write)
{ {
$error=0; $error = 0;
if (empty($ref)) if (empty($ref))
{ {
@ -144,10 +144,10 @@ if (empty($reshook))
$error++; $error++;
} }
if (! $error) if (!$error)
{ {
$res = $object->fetch($id); $res = $object->fetch($id);
if ( $res > 0 ) if ($res > 0)
{ {
$object->ref = $ref; $object->ref = $ref;
$object->description = $description; $object->description = $description;
@ -157,10 +157,10 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object); $ret = $extrafields->setOptionalsFromPost(null, $object);
if ($ret < 0) { if ($ret < 0) {
$error ++; $error++;
} }
$result=$object->update($user); $result = $object->update($user);
if ($result > 0) if ($result > 0)
{ {
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
@ -181,14 +181,14 @@ if (empty($reshook))
if ($error) if ($error)
{ {
$action='edit'; $action = 'edit';
} }
} }
if ($action == 'confirm_delete_resource' && $user->rights->resource->delete && $confirm === 'yes') if ($action == 'confirm_delete_resource' && $user->rights->resource->delete && $confirm === 'yes')
{ {
$res = $object->fetch($id); $res = $object->fetch($id);
if($res > 0) if ($res > 0)
{ {
$result = $object->delete($id); $result = $object->delete($id);
@ -236,13 +236,13 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0)
if ($action == 'create' || $action == 'edit') if ($action == 'create' || $action == 'edit')
{ {
if (! $user->rights->resource->write) accessforbidden('', 0, 1); if (!$user->rights->resource->write) accessforbidden('', 0, 1);
// Create/Edit object // Create/Edit object
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">'; print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="'.($action == "create"?"add":"update").'">'; print '<input type="hidden" name="action" value="'.($action == "create" ? "add" : "update").'">';
print '<table class="border centpercent">'; print '<table class="border centpercent">';
@ -271,8 +271,8 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0)
print '</td></tr>'; print '</td></tr>';
// Other attributes // Other attributes
$parameters=array('objectsrc' => $objectsrc); $parameters = array('objectsrc' => $objectsrc);
$reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
if (empty($reshook)) if (empty($reshook))
{ {
@ -284,9 +284,9 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0)
dol_fiche_end(); dol_fiche_end();
print '<div class="center">'; print '<div class="center">';
print '<input type="submit" class="button" name="save" value="' . $langs->trans($action == "create"?"Create":"Modify") . '">'; print '<input type="submit" class="button" name="save" value="'.$langs->trans($action == "create" ? "Create" : "Modify").'">';
print ' &nbsp; &nbsp; '; print ' &nbsp; &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="' . $langs->trans("Cancel") . '">'; print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>'; print '</div>';
print '</div>'; print '</div>';
@ -306,11 +306,11 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0)
print $formconfirm; print $formconfirm;
$linkback = '<a href="' . DOL_URL_ROOT . '/resource/list.php' . (! empty($socid) ? '?id=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php'.(!empty($socid) ? '?id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
$morehtmlref='<div class="refidno">'; $morehtmlref = '<div class="refidno">';
$morehtmlref.='</div>'; $morehtmlref .= '</div>';
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
@ -326,7 +326,7 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0)
// Resource type // Resource type
print '<tr>'; print '<tr>';
print '<td class="titlefield">' . $langs->trans("ResourceType") . '</td>'; print '<td class="titlefield">'.$langs->trans("ResourceType").'</td>';
print '<td>'; print '<td>';
print $object->type_label; print $object->type_label;
print '</td>'; print '</td>';
@ -334,13 +334,13 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0)
// Description // Description
print '<tr>'; print '<tr>';
print '<td>' . $langs->trans("ResourceFormLabel_description") . '</td>'; print '<td>'.$langs->trans("ResourceFormLabel_description").'</td>';
print '<td>'; print '<td>';
print $object->description; print $object->description;
print '</td>'; print '</td>';
// Other attributes // Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
print '</tr>'; print '</tr>';
@ -371,10 +371,10 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0)
// modified by hook // modified by hook
if (empty($reshook)) if (empty($reshook))
{ {
if ($action != "create" && $action != "edit" ) if ($action != "create" && $action != "edit")
{ {
// Edit resource // Edit resource
if($user->rights->resource->write) if ($user->rights->resource->write)
{ {
print '<div class="inline-block divButAction">'; print '<div class="inline-block divButAction">';
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=edit" class="butAction">'.$langs->trans('Modify').'</a>'; print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=edit" class="butAction">'.$langs->trans('Modify').'</a>';
@ -384,7 +384,7 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0)
if ($action != "delete" && $action != "create" && $action != "edit") if ($action != "delete" && $action != "create" && $action != "edit")
{ {
// Delete resource // Delete resource
if($user->rights->resource->delete) if ($user->rights->resource->delete)
{ {
print '<div class="inline-block divButAction">'; print '<div class="inline-block divButAction">';
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete" class="butActionDelete">'.$langs->trans('Delete').'</a>'; print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete" class="butActionDelete">'.$langs->trans('Delete').'</a>';

View File

@ -28,12 +28,12 @@ require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
if (! empty($conf->projet->enabled)) { if (!empty($conf->projet->enabled)) {
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
} }
if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
} }
// Load translation files required by the page // Load translation files required by the page
@ -45,19 +45,19 @@ $sortfield = GETPOST('sortfield','alpha');
$page = GETPOST('page','int'); $page = GETPOST('page','int');
*/ */
if( ! $user->rights->resource->read) if (!$user->rights->resource->read)
accessforbidden(); accessforbidden();
$object=new Dolresource($db); $object = new Dolresource($db);
$hookmanager->initHooks(array('element_resource')); $hookmanager->initHooks(array('element_resource'));
$object->available_resources = array('dolresource'); $object->available_resources = array('dolresource');
// Get parameters // Get parameters
$id = GETPOST('id', 'int'); // resource id $id = GETPOST('id', 'int'); // resource id
$element_id = GETPOST('element_id', 'int'); // element_id $element_id = GETPOST('element_id', 'int'); // element_id
$element_ref = GETPOST('ref', 'alpha'); // element ref $element_ref = GETPOST('ref', 'alpha'); // element ref
$element = GETPOST('element', 'alpha'); // element_type $element = GETPOST('element', 'alpha'); // element_type
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$mode = GETPOST('mode', 'alpha'); $mode = GETPOST('mode', 'alpha');
$lineid = GETPOST('lineid', 'int'); $lineid = GETPOST('lineid', 'int');
@ -89,14 +89,14 @@ if (empty($reshook))
{ {
$error = 0; $error = 0;
if ($action == 'add_element_resource' && ! $cancel) if ($action == 'add_element_resource' && !$cancel)
{ {
$res = 0; $res = 0;
if (! ($resource_id > 0)) if (!($resource_id > 0))
{ {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Resource")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Resource")), null, 'errors');
$action=''; $action = '';
} }
else else
{ {
@ -105,7 +105,7 @@ if (empty($reshook))
// TODO : add this check at update_linked_resource and when modifying event start or end date // TODO : add this check at update_linked_resource and when modifying event start or end date
// check if an event resource is already in use // check if an event resource is already in use
if (!empty($conf->global->RESOURCE_USED_IN_EVENT_CHECK) && $objstat->element=='action' && $resource_type=='dolresource' && intval($busy)==1) { if (!empty($conf->global->RESOURCE_USED_IN_EVENT_CHECK) && $objstat->element == 'action' && $resource_type == 'dolresource' && intval($busy) == 1) {
$eventDateStart = $objstat->datep; $eventDateStart = $objstat->datep;
$eventDateEnd = $objstat->datef; $eventDateEnd = $objstat->datef;
$isFullDayEvent = intval($objstat->fulldayevent); $isFullDayEvent = intval($objstat->fulldayevent);
@ -118,24 +118,24 @@ if (empty($reshook))
} }
$sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label"; $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
$sql .= " FROM " . MAIN_DB_PREFIX . "element_resources as er"; $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "resource as r ON r.rowid = er.resource_id AND er.resource_type = '" . $db->escape($resource_type) . "'"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($resource_type)."'";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "actioncomm as ac ON ac.id = er.element_id AND er.element_type = '" . $db->escape($objstat->element) . "'"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($objstat->element)."'";
$sql .= " WHERE er.resource_id = " . $resource_id; $sql .= " WHERE er.resource_id = ".$resource_id;
$sql .= " AND er.busy = 1"; $sql .= " AND er.busy = 1";
$sql .= " AND ("; $sql .= " AND (";
// event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end) // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
$sql .= " (ac.datep <= '" . $db->idate($eventDateStart) . "' AND (ac.datep2 IS NULL OR ac.datep2 >= '" . $db->idate($eventDateStart) . "'))"; $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))";
// event date end between ac.datep and ac.datep2 // event date end between ac.datep and ac.datep2
if (!empty($eventDateEnd)) { if (!empty($eventDateEnd)) {
$sql .= " OR (ac.datep <= '" . $db->idate($eventDateEnd) . "' AND (ac.datep2 >= '" . $db->idate($eventDateEnd) . "'))"; $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 >= '".$db->idate($eventDateEnd)."'))";
} }
// event date start before ac.datep and event date end after ac.datep2 // event date start before ac.datep and event date end after ac.datep2
$sql .= " OR ("; $sql .= " OR (";
$sql .= "ac.datep >= '" . $db->idate($eventDateStart) . "'"; $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'";
if (!empty($eventDateEnd)) { if (!empty($eventDateEnd)) {
$sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '" . $db->idate($eventDateEnd) . "')"; $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')";
} }
$sql .= ")"; $sql .= ")";
@ -146,12 +146,12 @@ if (empty($reshook))
$objstat->error = $db->lasterror(); $objstat->error = $db->lasterror();
$objstat->errors[] = $objstat->error; $objstat->errors[] = $objstat->error;
} else { } else {
if ($db->num_rows($resql)>0) { if ($db->num_rows($resql) > 0) {
// already in use // already in use
$error++; $error++;
$objstat->error = $langs->trans('ErrorResourcesAlreadyInUse') . ' : '; $objstat->error = $langs->trans('ErrorResourcesAlreadyInUse').' : ';
while ($obj = $db->fetch_object($resql)) { while ($obj = $db->fetch_object($resql)) {
$objstat->error .= '<br> - ' . $langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label . ' [' . $obj->ac_id . ']'); $objstat->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']');
} }
$objstat->errors[] = $objstat->error; $objstat->errors[] = $objstat->error;
} }
@ -164,7 +164,7 @@ if (empty($reshook))
} }
} }
if (! $error && $res > 0) if (!$error && $res > 0)
{ {
setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs'); setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs');
header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id); header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id);
@ -177,15 +177,15 @@ if (empty($reshook))
} }
// Update ressource // Update ressource
if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel', 'alpha') ) if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel', 'alpha'))
{ {
$res = $object->fetch_element_resource($lineid); $res = $object->fetch_element_resource($lineid);
if($res) if ($res)
{ {
$object->busy = $busy; $object->busy = $busy;
$object->mandatory = $mandatory; $object->mandatory = $mandatory;
if (!empty($conf->global->RESOURCE_USED_IN_EVENT_CHECK) && $object->element_type=='action' && $object->resource_type=='dolresource' && intval($object->busy)==1) { if (!empty($conf->global->RESOURCE_USED_IN_EVENT_CHECK) && $object->element_type == 'action' && $object->resource_type == 'dolresource' && intval($object->busy) == 1) {
$eventDateStart = $object->objelement->datep; $eventDateStart = $object->objelement->datep;
$eventDateEnd = $object->objelement->datef; $eventDateEnd = $object->objelement->datef;
$isFullDayEvent = intval($objstat->fulldayevent); $isFullDayEvent = intval($objstat->fulldayevent);
@ -198,25 +198,25 @@ if (empty($reshook))
} }
$sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label"; $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
$sql .= " FROM " . MAIN_DB_PREFIX . "element_resources as er"; $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "resource as r ON r.rowid = er.resource_id AND er.resource_type = '" . $db->escape($object->resource_type) . "'"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($object->resource_type)."'";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "actioncomm as ac ON ac.id = er.element_id AND er.element_type = '" . $db->escape($object->element_type) . "'"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($object->element_type)."'";
$sql .= " WHERE er.resource_id = " . $object->resource_id; $sql .= " WHERE er.resource_id = ".$object->resource_id;
$sql .= " AND ac.id != " . $object->element_id; $sql .= " AND ac.id != ".$object->element_id;
$sql .= " AND er.busy = 1"; $sql .= " AND er.busy = 1";
$sql .= " AND ("; $sql .= " AND (";
// event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end) // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
$sql .= " (ac.datep <= '" . $db->idate($eventDateStart) . "' AND (ac.datep2 IS NULL OR ac.datep2 >= '" . $db->idate($eventDateStart) . "'))"; $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))";
// event date end between ac.datep and ac.datep2 // event date end between ac.datep and ac.datep2
if (!empty($eventDateEnd)) { if (!empty($eventDateEnd)) {
$sql .= " OR (ac.datep <= '" . $db->idate($eventDateEnd) . "' AND (ac.datep2 IS NULL OR ac.datep2 >= '" . $db->idate($eventDateEnd) . "'))"; $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateEnd)."'))";
} }
// event date start before ac.datep and event date end after ac.datep2 // event date start before ac.datep and event date end after ac.datep2
$sql .= " OR ("; $sql .= " OR (";
$sql .= "ac.datep >= '" . $db->idate($eventDateStart) . "'"; $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'";
if (!empty($eventDateEnd)) { if (!empty($eventDateEnd)) {
$sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '" . $db->idate($eventDateEnd) . "')"; $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')";
} }
$sql .= ")"; $sql .= ")";
@ -227,12 +227,12 @@ if (empty($reshook))
$object->error = $db->lasterror(); $object->error = $db->lasterror();
$object->errors[] = $object->error; $object->errors[] = $object->error;
} else { } else {
if ($db->num_rows($resql)>0) { if ($db->num_rows($resql) > 0) {
// already in use // already in use
$error++; $error++;
$object->error = $langs->trans('ErrorResourcesAlreadyInUse') . ' : '; $object->error = $langs->trans('ErrorResourcesAlreadyInUse').' : ';
while ($obj = $db->fetch_object($resql)) { while ($obj = $db->fetch_object($resql)) {
$object->error .= '<br> - ' . $langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label . ' [' . $obj->ac_id . ']'); $object->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']');
} }
$object->errors[] = $objstat->error; $object->errors[] = $objstat->error;
} }
@ -273,8 +273,8 @@ if (empty($reshook))
} }
} }
$parameters=array('resource_id'=>$resource_id); $parameters = array('resource_id'=>$resource_id);
$reshook=$hookmanager->executeHooks('getElementResources', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('getElementResources', $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');
@ -283,15 +283,15 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
* View * View
*/ */
$form=new Form($db); $form = new Form($db);
$pagetitle=$langs->trans('ResourceElementPage'); $pagetitle = $langs->trans('ResourceElementPage');
llxHeader('', $pagetitle, ''); llxHeader('', $pagetitle, '');
// Load available resource, declared by modules // Load available resource, declared by modules
$ret = count($object->available_resources); $ret = count($object->available_resources);
if($ret == -1) { if ($ret == -1) {
dol_print_error($db, $object->error); dol_print_error($db, $object->error);
exit; exit;
} }
@ -315,49 +315,49 @@ else
$act = fetchObjectByElement($element_id, $element, $element_ref); $act = fetchObjectByElement($element_id, $element, $element_ref);
if (is_object($act)) if (is_object($act))
{ {
$head=actions_prepare_head($act); $head = actions_prepare_head($act);
dol_fiche_head($head, 'resources', $langs->trans("Action"), -1, 'action'); dol_fiche_head($head, 'resources', $langs->trans("Action"), -1, 'action');
$linkback =img_picto($langs->trans("BackToList"), 'object_list', 'class="hideonsmartphone pictoactionview"'); $linkback = img_picto($langs->trans("BackToList"), 'object_list', 'class="hideonsmartphone pictoactionview"');
$linkback.= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php">'.$langs->trans("BackToList").'</a>'; $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php">'.$langs->trans("BackToList").'</a>';
// Link to other agenda views // Link to other agenda views
$out=''; $out = '';
$out.='</li><li class="noborder litext">'.img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="hideonsmartphone pictoactionview"'); $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="hideonsmartphone pictoactionview"');
$out.='<a href="'.DOL_URL_ROOT.'/comm/action/peruser.php?action=show_peruser&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">'.$langs->trans("ViewPerUser").'</a>'; $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/peruser.php?action=show_peruser&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">'.$langs->trans("ViewPerUser").'</a>';
$out.='</li><li class="noborder litext">'.img_picto($langs->trans("ViewCal"), 'object_calendar', 'class="hideonsmartphone pictoactionview"'); $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewCal"), 'object_calendar', 'class="hideonsmartphone pictoactionview"');
$out.='<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_month&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">'.$langs->trans("ViewCal").'</a>'; $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_month&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">'.$langs->trans("ViewCal").'</a>';
$out.='</li><li class="noborder litext">'.img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="hideonsmartphone pictoactionview"'); $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="hideonsmartphone pictoactionview"');
$out.='<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_day&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">'.$langs->trans("ViewWeek").'</a>'; $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_day&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">'.$langs->trans("ViewWeek").'</a>';
$out.='</li><li class="noborder litext">'.img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="hideonsmartphone pictoactionview"'); $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="hideonsmartphone pictoactionview"');
$out.='<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_day&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">'.$langs->trans("ViewDay").'</a>'; $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_day&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">'.$langs->trans("ViewDay").'</a>';
$linkback.=$out; $linkback .= $out;
$morehtmlref='<div class="refidno">'; $morehtmlref = '<div class="refidno">';
// Thirdparty // Thirdparty
//$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
// Project // Project
if (! empty($conf->projet->enabled)) if (!empty($conf->projet->enabled))
{ {
$langs->load("projects"); $langs->load("projects");
//$morehtmlref.='<br>'.$langs->trans('Project') . ' '; //$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
$morehtmlref.=$langs->trans('Project') . ': '; $morehtmlref .= $langs->trans('Project').': ';
if (! empty($act->fk_project)) { if (!empty($act->fk_project)) {
$proj = new Project($db); $proj = new Project($db);
$proj->fetch($act->fk_project); $proj->fetch($act->fk_project);
$morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $act->fk_project . '" title="' . $langs->trans('ShowProject') . '">'; $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$act->fk_project.'" title="'.$langs->trans('ShowProject').'">';
$morehtmlref.=$proj->ref; $morehtmlref .= $proj->ref;
$morehtmlref.='</a>'; $morehtmlref .= '</a>';
if ($proj->title) $morehtmlref.=' - '.$proj->title; if ($proj->title) $morehtmlref .= ' - '.$proj->title;
} else { } else {
$morehtmlref.=''; $morehtmlref .= '';
} }
} }
$morehtmlref.='</div>'; $morehtmlref .= '</div>';
dol_banner_tab($act, 'element_id', $linkback, ($user->socid?0:1), 'id', 'ref', $morehtmlref, '&element='.$element, 0, '', ''); dol_banner_tab($act, 'element_id', $linkback, ($user->socid ? 0 : 1), 'id', 'ref', $morehtmlref, '&element='.$element, 0, '', '');
print '<div class="fichecenter">'; print '<div class="fichecenter">';
@ -366,7 +366,7 @@ else
print '<table class="border tableforfield" width="100%">'; print '<table class="border tableforfield" width="100%">';
// Type // Type
if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) if (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
{ {
print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td colspan="3">'.$act->type.'</td></tr>'; print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td colspan="3">'.$act->type.'</td></tr>';
} }
@ -376,7 +376,7 @@ else
// Date start // Date start
print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">';
if (! $act->fulldayevent) print dol_print_date($act->datep, 'dayhour'); if (!$act->fulldayevent) print dol_print_date($act->datep, 'dayhour');
else print dol_print_date($act->datep, 'day'); else print dol_print_date($act->datep, 'day');
if ($act->percentage == 0 && $act->datep && $act->datep < ($now - $delay_warning)) print img_warning($langs->trans("Late")); if ($act->percentage == 0 && $act->datep && $act->datep < ($now - $delay_warning)) print img_warning($langs->trans("Late"));
print '</td>'; print '</td>';
@ -384,9 +384,9 @@ else
// Date end // Date end
print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
if (! $act->fulldayevent) print dol_print_date($act->datef, 'dayhour'); if (!$act->fulldayevent) print dol_print_date($act->datef, 'dayhour');
else print dol_print_date($act->datef, 'day'); else print dol_print_date($act->datef, 'day');
if ($act->percentage > 0 && $act->percentage < 100 && $act->datef && $act->datef < ($now- $delay_warning)) print img_warning($langs->trans("Late")); if ($act->percentage > 0 && $act->percentage < 100 && $act->datef && $act->datef < ($now - $delay_warning)) print img_warning($langs->trans("Late"));
print '</td></tr>'; print '</td></tr>';
// Location // Location
@ -397,32 +397,32 @@ else
// Assigned to // Assigned to
print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">'; print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
$listofuserid=array(); $listofuserid = array();
if (empty($donotclearsession)) if (empty($donotclearsession))
{ {
if ($act->userownerid > 0) $listofuserid[$act->userownerid]=array('id'=>$act->userownerid,'transparency'=>$act->transparency); // Owner first if ($act->userownerid > 0) $listofuserid[$act->userownerid] = array('id'=>$act->userownerid, 'transparency'=>$act->transparency); // Owner first
if (! empty($act->userassigned)) // Now concat assigned users if (!empty($act->userassigned)) // Now concat assigned users
{ {
// Restore array with key with same value than param 'id' // Restore array with key with same value than param 'id'
$tmplist1=$act->userassigned; $tmplist2=array(); $tmplist1 = $act->userassigned; $tmplist2 = array();
foreach($tmplist1 as $key => $val) foreach ($tmplist1 as $key => $val)
{ {
if ($val['id'] && $val['id'] != $act->userownerid) $listofuserid[$val['id']]=$val; if ($val['id'] && $val['id'] != $act->userownerid) $listofuserid[$val['id']] = $val;
} }
} }
$_SESSION['assignedtouser']=json_encode($listofuserid); $_SESSION['assignedtouser'] = json_encode($listofuserid);
} }
else else
{ {
if (!empty($_SESSION['assignedtouser'])) if (!empty($_SESSION['assignedtouser']))
{ {
$listofuserid=json_decode($_SESSION['assignedtouser'], true); $listofuserid = json_decode($_SESSION['assignedtouser'], true);
} }
} }
$listofcontactid=array(); // not used yet $listofcontactid = array(); // not used yet
$listofotherid=array(); // not used yet $listofotherid = array(); // not used yet
print '<div class="assignedtouser">'; print '<div class="assignedtouser">';
print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', ($act->datep != $act->datef)?1:0, $listofuserid, $listofcontactid, $listofotherid); print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', ($act->datep != $act->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
print '</div>'; print '</div>';
/*if (in_array($user->id,array_keys($listofuserid))) /*if (in_array($user->id,array_keys($listofuserid)))
{ {
@ -448,7 +448,7 @@ else
$savobject = $object; $savobject = $object;
$object = $socstatic; $object = $socstatic;
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
$head = societe_prepare_head($socstatic); $head = societe_prepare_head($socstatic);
dol_fiche_head($head, 'resources', $langs->trans("ThirdParty"), -1, 'company'); dol_fiche_head($head, 'resources', $langs->trans("ThirdParty"), -1, 'company');
@ -461,7 +461,7 @@ else
print '<table class="border centpercent">'; print '<table class="border centpercent">';
// Alias name (commercial, trademark or alias name) // Alias name (commercial, trademark or alias name)
print '<tr><td class="titlefield">' . $langs->trans('AliasNames') . '</td><td colspan="3">'; print '<tr><td class="titlefield">'.$langs->trans('AliasNames').'</td><td colspan="3">';
print $socstatic->name_alias; print $socstatic->name_alias;
print "</td></tr>"; print "</td></tr>";
@ -486,53 +486,53 @@ else
if (is_object($fichinter)) if (is_object($fichinter))
{ {
$head=fichinter_prepare_head($fichinter); $head = fichinter_prepare_head($fichinter);
dol_fiche_head($head, 'resource', $langs->trans("InterventionCard"), -1, 'intervention'); dol_fiche_head($head, 'resource', $langs->trans("InterventionCard"), -1, 'intervention');
// Intervention card // Intervention card
$linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
$morehtmlref='<div class="refidno">'; $morehtmlref = '<div class="refidno">';
// Ref customer // Ref customer
//$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
//$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
// Thirdparty // Thirdparty
$morehtmlref.=$langs->trans('ThirdParty') . ' : ' . $fichinter->thirdparty->getNomUrl(1); $morehtmlref .= $langs->trans('ThirdParty').' : '.$fichinter->thirdparty->getNomUrl(1);
// Project // Project
if (! empty($conf->projet->enabled)) if (!empty($conf->projet->enabled))
{ {
$langs->load("projects"); $langs->load("projects");
$morehtmlref.='<br>'.$langs->trans('Project') . ' '; $morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->commande->creer) if ($user->rights->commande->creer)
{ {
if ($action != 'classify') if ($action != 'classify')
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $fichinter->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $fichinter->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref.=' : '; $morehtmlref .= ' : ';
if ($action == 'classify') { if ($action == 'classify') {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $fichinter->id, $fichinter->socid, $fichinter->fk_project, 'projectid', 0, 0, 1, 1); //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $fichinter->id, $fichinter->socid, $fichinter->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$fichinter->id.'">'; $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$fichinter->id.'">';
$morehtmlref.='<input type="hidden" name="action" value="classin">'; $morehtmlref .= '<input type="hidden" name="action" value="classin">';
$morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; $morehtmlref .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$morehtmlref.=$formproject->select_projects($fichinter->socid, $fichinter->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref .= $formproject->select_projects($fichinter->socid, $fichinter->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
$morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref.='</form>'; $morehtmlref .= '</form>';
} else { } else {
$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $fichinter->id, $fichinter->socid, $fichinter->fk_project, 'none', 0, 0, 0, 1); $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$fichinter->id, $fichinter->socid, $fichinter->fk_project, 'none', 0, 0, 0, 1);
} }
} else { } else {
if (! empty($fichinter->fk_project)) { if (!empty($fichinter->fk_project)) {
$proj = new Project($db); $proj = new Project($db);
$proj->fetch($fichinter->fk_project); $proj->fetch($fichinter->fk_project);
$morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $fichinter->fk_project . '" title="' . $langs->trans('ShowProject') . '">'; $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$fichinter->fk_project.'" title="'.$langs->trans('ShowProject').'">';
$morehtmlref.=$proj->ref; $morehtmlref .= $proj->ref;
$morehtmlref.='</a>'; $morehtmlref .= '</a>';
} else { } else {
$morehtmlref.=''; $morehtmlref .= '';
} }
} }
} }
$morehtmlref.='</div>'; $morehtmlref .= '</div>';
dol_banner_tab($fichinter, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '&element='.$element, 0, '', '', 1); dol_banner_tab($fichinter, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '&element='.$element, 0, '', '', 1);
@ -551,13 +551,13 @@ else
if (is_object($product)) if (is_object($product))
{ {
$head = product_prepare_head($product); $head = product_prepare_head($product);
$titre=$langs->trans("CardProduct".$product->type); $titre = $langs->trans("CardProduct".$product->type);
$picto=($product->type==Product::TYPE_SERVICE?'service':'product'); $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
dol_fiche_head($head, 'resources', $titre, -1, $picto); dol_fiche_head($head, 'resources', $titre, -1, $picto);
$shownav = 1; $shownav = 1;
if ($user->socid && ! in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0;
dol_banner_tab($product, 'ref', '', $shownav, 'ref', 'ref', '', '&element='.$element); dol_banner_tab($product, 'ref', '', $shownav, 'ref', 'ref', '', '&element='.$element);
dol_fiche_end(); dol_fiche_end();
@ -566,8 +566,8 @@ else
// hook for other elements linked // hook for other elements linked
$parameters=array('element'=>$element, 'element_id'=>$element_id, 'element_ref'=>$element_ref); $parameters = array('element'=>$element, 'element_id'=>$element_id, 'element_ref'=>$element_ref);
$reshook=$hookmanager->executeHooks('printElementTab', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('printElementTab', $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');
@ -578,26 +578,26 @@ else
foreach ($object->available_resources as $modresources => $resources) foreach ($object->available_resources as $modresources => $resources)
{ {
$resources=(array) $resources; // To be sure $resources is an array $resources = (array) $resources; // To be sure $resources is an array
foreach($resources as $resource_obj) foreach ($resources as $resource_obj)
{ {
$element_prop = getElementProperties($resource_obj); $element_prop = getElementProperties($resource_obj);
//print '/'.$modresources.'/class/'.$resource_obj.'.class.php<br>'; //print '/'.$modresources.'/class/'.$resource_obj.'.class.php<br>';
$path = ''; $path = '';
if(strpos($resource_obj, '@')) if (strpos($resource_obj, '@'))
$path .= '/'.$element_prop['module']; $path .= '/'.$element_prop['module'];
$linked_resources = $object->getElementResources($element, $element_id, $resource_obj); $linked_resources = $object->getElementResources($element, $element_id, $resource_obj);
// Output template part (modules that overwrite templates must declare this into descriptor) // Output template part (modules that overwrite templates must declare this into descriptor)
$defaulttpldir='/core/tpl'; $defaulttpldir = '/core/tpl';
$dirtpls=array_merge($conf->modules_parts['tpl'], array($defaulttpldir), array($path.$defaulttpldir)); $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir), array($path.$defaulttpldir));
foreach($dirtpls as $module => $reldir) foreach ($dirtpls as $module => $reldir)
{ {
if(file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php'))) if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php')))
{ {
$tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php'); $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php');
} }
@ -606,18 +606,18 @@ else
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_add.tpl.php'; $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_add.tpl.php';
} }
if (empty($conf->file->strict_mode)) { if (empty($conf->file->strict_mode)) {
$res=@include $tpl; $res = @include $tpl;
} else { } else {
$res=include $tpl; // for debug $res = include $tpl; // for debug
} }
if ($res) break; if ($res) break;
} }
if ($mode != 'add' || $resource_obj != $resource_type) if ($mode != 'add' || $resource_obj != $resource_type)
{ {
foreach($dirtpls as $module => $reldir) foreach ($dirtpls as $module => $reldir)
{ {
if(file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php'))) if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php')))
{ {
$tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php'); $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php');
} }
@ -626,9 +626,9 @@ else
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_view.tpl.php'; $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_view.tpl.php';
} }
if (empty($conf->file->strict_mode)) { if (empty($conf->file->strict_mode)) {
$res=@include $tpl; $res = @include $tpl;
} else { } else {
$res=include $tpl; // for debug $res = include $tpl; // for debug
} }
if ($res) break; if ($res) break;
} }

File diff suppressed because it is too large Load Diff

View File

@ -57,16 +57,16 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end
// We define date_start and date_end // We define date_start and date_end
$year_end = $year_start; $year_end = $year_start;
$month_start = GETPOST("month") ? GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); $month_start = GETPOST("month") ? GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
if (! GETPOST('month')) { if (!GETPOST('month')) {
if (! GETPOST("year") && $month_start > $month_current) { if (!GETPOST("year") && $month_start > $month_current) {
$year_start --; $year_start--;
$year_end --; $year_end--;
} }
$month_end = $month_start - 1; $month_end = $month_start - 1;
if ($month_end < 1) if ($month_end < 1)
$month_end = 12; $month_end = 12;
else else
$year_end ++; $year_end++;
} else } else
$month_end = $month_start; $month_end = $month_start;
$date_start = dol_get_first_day($year_start, $month_start, false); $date_start = dol_get_first_day($year_start, $month_start, false);
@ -100,11 +100,11 @@ $periodlink = '';
$exportlink = ''; $exportlink = '';
$nom = $langs->trans("ReportThirdParty"); $nom = $langs->trans("ReportThirdParty");
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0) . ' - ' . $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
$description = $langs->trans("DescThirdPartyReport"); $description = $langs->trans("DescThirdPartyReport");
$builddate=dol_now(); $builddate = dol_now();
$moreparam=array('action' => ''); $moreparam = array('action' => '');
report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam); report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam);
print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />'; print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />';
@ -121,36 +121,36 @@ print '
$sql = "(SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta as compta , "; $sql = "(SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta as compta , ";
$sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , f.datec , f.fk_soc , cp.label as country "; $sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , f.datec , f.fk_soc , cp.label as country ";
$sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= ", " . MAIN_DB_PREFIX . "facture as f"; $sql .= ", ".MAIN_DB_PREFIX."facture as f";
$sql .= ", " . MAIN_DB_PREFIX . "c_country as cp"; $sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
$sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND s.fk_pays = cp.rowid"; $sql .= " AND s.fk_pays = cp.rowid";
if (! empty($date_start) && ! empty($date_end)) if (!empty($date_start) && !empty($date_end))
$sql .= " AND f.datec >= '" . $db->idate($date_start) . "' AND f.datec <= '" . $db->idate($date_end) . "'"; $sql .= " AND f.datec >= '".$db->idate($date_start)."' AND f.datec <= '".$db->idate($date_end)."'";
$sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; $sql .= " AND f.entity IN (".getEntity('invoice', 0).")";
if ($socid) if ($socid)
$sql .= " AND f.fk_soc = " . $socid; $sql .= " AND f.fk_soc = ".$socid;
$sql .= " GROUP BY name"; $sql .= " GROUP BY name";
$sql .= ")"; $sql .= ")";
$sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , "; $sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , ";
$sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , ff.datec , ff.fk_soc , cp.label as country "; $sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , ff.datec , ff.fk_soc , cp.label as country ";
$sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= ", " . MAIN_DB_PREFIX . "facture_fourn as ff"; $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as ff";
$sql .= ", " . MAIN_DB_PREFIX . "c_country as cp"; $sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
$sql .= " WHERE ff.fk_soc = s.rowid"; $sql .= " WHERE ff.fk_soc = s.rowid";
$sql .= " AND s.fk_pays = cp.rowid"; $sql .= " AND s.fk_pays = cp.rowid";
if (! empty($date_start) && ! empty($date_end)) if (!empty($date_start) && !empty($date_end))
$sql .= " AND ff.datec >= '" . $db->idate($date_start) . "' AND ff.datec <= '" . $db->idate($date_end) . "'"; $sql .= " AND ff.datec >= '".$db->idate($date_start)."' AND ff.datec <= '".$db->idate($date_end)."'";
$sql .= " AND ff.entity = " . $conf->entity; $sql .= " AND ff.entity = ".$conf->entity;
if ($socid) if ($socid)
$sql .= " AND f.fk_soc = " . $socid; $sql .= " AND f.fk_soc = ".$socid;
$sql .= " GROUP BY name"; $sql .= " GROUP BY name";
$sql .= ")"; $sql .= ")";
$sql .= "ORDER BY name ASC"; $sql .= "ORDER BY name ASC";
dol_syslog('accountancy/admin/thirdpartyaccount.php:: $sql=' . $sql); dol_syslog('accountancy/admin/thirdpartyaccount.php:: $sql='.$sql);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
@ -163,15 +163,15 @@ if ($resql) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
print '"' . $obj->compta . '",'; print '"'.$obj->compta.'",';
print '"' . $obj->address . '",'; print '"'.$obj->address.'",';
print '"' . $obj->zip . '",'; print '"'.$obj->zip.'",';
print '"' . $obj->town . '",'; print '"'.$obj->town.'",';
print '"' . $obj->country . '",'; print '"'.$obj->country.'",';
print '"' . $obj->phone . '",'; print '"'.$obj->phone.'",';
print '"' . $obj->fax . '",'; print '"'.$obj->fax.'",';
print "\n"; print "\n";
$i ++; $i++;
} }
/* /*
@ -187,16 +187,16 @@ if ($resql) {
print '</td><td valign="top" width="70%" class="notopnoleftnoright"></td>'; print '</td><td valign="top" width="70%" class="notopnoleftnoright"></td>';
print '</tr><tr><td colspan=2>'; print '</tr><tr><td colspan=2>';
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td class="left">' . $langs->trans("ThirdParties") . '</td>'; print '<tr class="liste_titre"><td class="left">'.$langs->trans("ThirdParties").'</td>';
print '<td class="left">' . $langs->trans("AccountNumber") . '</td>'; print '<td class="left">'.$langs->trans("AccountNumber").'</td>';
print '<td class="left">' . $langs->trans("RaisonSociale") . '</td>'; print '<td class="left">'.$langs->trans("RaisonSociale").'</td>';
print '<td class="left">' . $langs->trans("Address") . '</td>'; print '<td class="left">'.$langs->trans("Address").'</td>';
print '<td class="left">' . $langs->trans("Zip") . '</td>'; print '<td class="left">'.$langs->trans("Zip").'</td>';
print '<td class="left">' . $langs->trans("Town") . '</td>'; print '<td class="left">'.$langs->trans("Town").'</td>';
print '<td class="left">' . $langs->trans("Country") . '</td>'; print '<td class="left">'.$langs->trans("Country").'</td>';
print '<td class="left">' . $langs->trans("Contact") . '</td>'; print '<td class="left">'.$langs->trans("Contact").'</td>';
print '<td class="left">' . $langs->trans("Phone") . '</td>'; print '<td class="left">'.$langs->trans("Phone").'</td>';
print '<td class="left">' . $langs->trans("Fax") . '</td></tr>'; print '<td class="left">'.$langs->trans("Fax").'</td></tr>';
while ($obj = $db->fetch_object($resql)) while ($obj = $db->fetch_object($resql))
{ {
@ -209,18 +209,18 @@ if ($resql) {
$thirdpartystatic->status = $obj->status; $thirdpartystatic->status = $obj->status;
print $thirdpartystatic->getNomUrl(1); print $thirdpartystatic->getNomUrl(1);
print '</td>'; print '</td>';
print '<td class="left">' . $obj->compta . '</td>' . "\n"; print '<td class="left">'.$obj->compta.'</td>'."\n";
print '<td class="left"></td>'; print '<td class="left"></td>';
print '<td class="left">' . $obj->address . '</td>'; print '<td class="left">'.$obj->address.'</td>';
print '<td class="left">' . $obj->zip . '</td>'; print '<td class="left">'.$obj->zip.'</td>';
print '<td class="left">' . $obj->town . '</td>'; print '<td class="left">'.$obj->town.'</td>';
print '<td class="left">' . $obj->country . '</td>'; print '<td class="left">'.$obj->country.'</td>';
print '<td class="left"></td>'; print '<td class="left"></td>';
print '<td class="left">' . $obj->phone . '</td>'; print '<td class="left">'.$obj->phone.'</td>';
print '<td class="left">' . $obj->fax . '</td>'; print '<td class="left">'.$obj->fax.'</td>';
print "</tr>\n"; print "</tr>\n";
$i ++; $i++;
} }
print "</table>"; print "</table>";