Merge branch '14.0' of git@github.com:Dolibarr/dolibarr.git into develop
Conflicts: htdocs/accountancy/customer/index.php htdocs/compta/facture/card.php htdocs/reception/card.php
This commit is contained in:
commit
fbce09f21b
@ -632,16 +632,20 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange
|
||||
print '<td width="60" class="right">'.$langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT)).'</td>';
|
||||
}
|
||||
print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
|
||||
|
||||
$sql = "SELECT '".$db->escape($langs->trans("Vide"))."' AS marge,";
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
$j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
|
||||
if ($j > 12) {
|
||||
$j -= 12;
|
||||
}
|
||||
$sql .= " SUM(".$db->ifsql("MONTH(f.datef)=".$j, "(fd.total_ht-(fd.qty * fd.buy_price_ht))", "0").") AS month".str_pad($j, 2, "0", STR_PAD_LEFT).",";
|
||||
$sql .= ' SUM('.$db->ifsql('MONTH(f.datef)='.$j,
|
||||
' ('.$db->ifsql('fd.total_ht < 0',
|
||||
' (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))',
|
||||
' (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))').')',
|
||||
0).') AS month'.str_pad($j, 2, '0', STR_PAD_LEFT).',';
|
||||
}
|
||||
$sql .= " SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as total";
|
||||
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
|
||||
$sql .= " WHERE f.datef >= '".$db->idate($search_date_start)."'";
|
||||
@ -658,7 +662,6 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange
|
||||
} else {
|
||||
$sql .= " AND f.type IN (".Facture::TYPE_STANDARD.", ".Facture::TYPE_REPLACEMENT.", ".Facture::TYPE_CREDIT_NOTE.", ".Facture::TYPE_DEPOSIT.", ".Facture::TYPE_SITUATION.")";
|
||||
}
|
||||
|
||||
dol_syslog('htdocs/accountancy/customer/index.php');
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
|
||||
@ -34,10 +34,12 @@ $ref = GETPOST('ref', 'alpha');
|
||||
|
||||
// Security check
|
||||
$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
|
||||
|
||||
$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
|
||||
if ($user->socid) {
|
||||
$socid = $user->socid;
|
||||
}
|
||||
|
||||
$result = restrictedArea($user, 'banque', $fieldvalue, 'bank_account', '', '', $fieldtype);
|
||||
if (empty($user->rights->banque->lire) && !$user->rights->banque->consolidate) {
|
||||
accessforbidden();
|
||||
|
||||
@ -51,7 +51,7 @@ if (!empty($conf->salaries->enabled)) {
|
||||
}
|
||||
|
||||
|
||||
$id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('account', 'int'));
|
||||
$id = (GETPOST('rowid', 'int') ? GETPOST('rowid', 'int') : GETPOST('account', 'int'));
|
||||
$ref = GETPOST('ref', 'alpha');
|
||||
$action = GETPOST('action', 'aZ09');
|
||||
$confirm = GETPOST('confirm', 'alpha');
|
||||
@ -67,6 +67,7 @@ $socid = 0;
|
||||
if ($user->socid) {
|
||||
$socid = $user->socid;
|
||||
}
|
||||
|
||||
$result = restrictedArea($user, 'banque', $fieldvalue, 'bank_account', '', '', $fieldtype);
|
||||
if (empty($user->rights->banque->lire) && !$user->rights->banque->consolidate) {
|
||||
accessforbidden();
|
||||
|
||||
@ -987,10 +987,13 @@ if (empty($reshook)) {
|
||||
$object->fetch($id);
|
||||
if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0) {
|
||||
$paiement = new Paiement($db);
|
||||
$result = $paiement->fetch(GETPOST('paiement_id'));
|
||||
$result = $paiement->fetch(GETPOST('paiement_id', 'int'));
|
||||
if ($result > 0) {
|
||||
$result = $paiement->delete(); // If fetch ok and found
|
||||
header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
|
||||
if ($result >= 0) {
|
||||
header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($result < 0) {
|
||||
setEventMessages($paiement->error, $paiement->errors, 'errors');
|
||||
@ -3871,7 +3874,6 @@ if ($action == 'create') {
|
||||
// For example print 239.2 - 229.3 - 9.9; does not return 0.
|
||||
// $resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
|
||||
// $resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
|
||||
|
||||
$resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
|
||||
|
||||
// Multicurrency
|
||||
@ -3880,7 +3882,10 @@ if ($action == 'create') {
|
||||
$multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
|
||||
$multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
|
||||
$multicurrency_resteapayer = price2num($object->multicurrency_total_ttc - $multicurrency_totalpaye - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits, 'MT');
|
||||
$resteapayer = price2num($multicurrency_resteapayer / $object->multicurrency_tx, 'MT');
|
||||
// Code to fix case of corrupted data
|
||||
if ($resteapayer == 0 && $multicurrency_resteapayer != 0) {
|
||||
$resteapayer = price2num($multicurrency_resteapayer / $object->multicurrency_tx, 'MT');
|
||||
}
|
||||
}
|
||||
|
||||
if ($object->paye) {
|
||||
@ -5356,7 +5361,7 @@ if ($action == 'create') {
|
||||
$discount = new DiscountAbsolute($db);
|
||||
$result = $discount->fetch(0, $object->id);
|
||||
|
||||
// Reopen a standard paid invoice
|
||||
// Reopen an invoice
|
||||
if ((($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT)
|
||||
|| ($object->type == Facture::TYPE_CREDIT_NOTE && empty($discount->id))
|
||||
|| ($object->type == Facture::TYPE_DEPOSIT && empty($discount->id))
|
||||
@ -5421,14 +5426,18 @@ if ($action == 'create') {
|
||||
if ($objectidnext) {
|
||||
print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseReplacedInvoice").'">'.$langs->trans('DoPayment').'</span>';
|
||||
} else {
|
||||
//if ($resteapayer == 0) { // Sometimes we can receive more, so we accept to enter more and will offer a button to convert into discount (but it is not a credit note, just a prepayment done)
|
||||
// print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="' . $langs->trans("DisabledBecauseRemainderToPayIsZero") . '">' . $langs->trans('DoPayment') . '</span></div>';
|
||||
//} else {
|
||||
if ($object->type == Facture::TYPE_DEPOSIT && $resteapayer == 0) {
|
||||
// For down payment, we refuse to receive more than amount to pay.
|
||||
print '<span class="butActionRefused" title="'.$langs->trans("DisabledBecauseRemainderToPayIsZero").'">'.$langs->trans('DoPayment').'</span>';
|
||||
} else {
|
||||
// Sometimes we can receive more, so we accept to enter more and will offer a button to convert into discount (but it is not a credit note, just a prepayment done)
|
||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/paiement.php?facid='.$object->id.'&action=create&accountid='.$object->fk_account.'">'.$langs->trans('DoPayment').'</a>';
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sumofpayment = $object->getSommePaiement();
|
||||
|
||||
// Reverse back money or convert to reduction
|
||||
if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_SITUATION) {
|
||||
// For credit note only
|
||||
@ -5446,13 +5455,18 @@ if ($action == 'create') {
|
||||
}
|
||||
// For credit note
|
||||
if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == Facture::STATUS_VALIDATED && $object->paye == 0 && $usercancreate
|
||||
&& (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $object->getSommePaiement() == 0)
|
||||
&& (!empty($conf->global->INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $sumofpayment == 0)
|
||||
) {
|
||||
print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&action=converttoreduc" title="'.dol_escape_htmltag($langs->trans("ConfirmConvertToReduc2")).'">'.$langs->trans('ConvertToReduc').'</a>';
|
||||
}
|
||||
// For deposit invoice
|
||||
if ($object->type == Facture::TYPE_DEPOSIT && $usercancreate && $object->statut > 0 && empty($discount->id)) {
|
||||
print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&action=converttoreduc">'.$langs->trans('ConvertToReduc').'</a>';
|
||||
if (price2num($object->total_ttc, 'MT') == price2num($sumofpayment, 'MT')) {
|
||||
// We can close a down payment only if paid amount is same than amount of down payment (by definition)
|
||||
print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&action=converttoreduc">'.$langs->trans('ConvertToReduc').'</a>';
|
||||
} else {
|
||||
print '<span class="butActionRefused" title="'.$langs->trans("AmountPaidMustMatchAmountOfDownPayment").'">'.$langs->trans('ConvertToReduc').'</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5460,10 +5474,15 @@ if ($action == 'create') {
|
||||
if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0 && $usercanissuepayment && (
|
||||
($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && ($resteapayer <= 0 || (!empty($conf->global->INVOICE_CAN_ADD_PAYMENT_EVEN_IF_ALREADY_PAID) && $object->total_ttc == $resteapayer))) ||
|
||||
($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0) ||
|
||||
($object->type == Facture::TYPE_DEPOSIT && $object->total_ttc > 0 && ($resteapayer == 0 || (!empty($conf->global->INVOICE_CAN_ADD_PAYMENT_EVEN_IF_ALREADY_PAID) && $object->total_ttc == $resteapayer)))
|
||||
($object->type == Facture::TYPE_DEPOSIT && $object->total_ttc > 0)
|
||||
)
|
||||
) {
|
||||
print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&action=paid">'.$langs->trans('ClassifyPaid').'</a>';
|
||||
if ($object->type == Facture::TYPE_DEPOSIT && price2num($object->total_ttc, 'MT') != price2num($sumofpayment, 'MT')) {
|
||||
// We can close a down payment only if paid amount is same than amount of down payment (by definition)
|
||||
print '<span class="butActionRefused" title="'.$langs->trans("AmountPaidMustMatchAmountOfDownPayment").'">'.$langs->trans('ClassifyPaid').'</span>';
|
||||
} else {
|
||||
print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&action=paid">'.$langs->trans('ClassifyPaid').'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
// Classify 'closed not completely paid' (possible if validated and not yet filed paid)
|
||||
|
||||
@ -39,6 +39,7 @@ $id = GETPOST("facid", "int");
|
||||
$ref = GETPOST("ref", 'alpha');
|
||||
|
||||
$object = new Facture($db);
|
||||
|
||||
$extrafields = new ExtraFields($db);
|
||||
|
||||
// Fetch optionals attributes and labels
|
||||
@ -62,14 +63,6 @@ $result = restrictedArea($user, 'facture', $object->id, '', '', 'fk_soc', $field
|
||||
* View
|
||||
*/
|
||||
|
||||
if (empty($object->id)) {
|
||||
llxHeader();
|
||||
$langs->load('errors');
|
||||
echo '<div class="error">'.$langs->trans("ErrorRecordNotFound").'</div>';
|
||||
llxFooter();
|
||||
exit;
|
||||
}
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
$title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('Info');
|
||||
@ -77,6 +70,13 @@ $help_url = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
|
||||
|
||||
llxHeader('', $title, $help_url);
|
||||
|
||||
if (empty($object->id)) {
|
||||
$langs->load('errors');
|
||||
echo '<div class="error">'.$langs->trans("ErrorRecordNotFound").'</div>';
|
||||
llxFooter();
|
||||
exit;
|
||||
}
|
||||
|
||||
$object->fetch_thirdparty();
|
||||
|
||||
$object->info($object->id);
|
||||
|
||||
@ -483,7 +483,7 @@ class Paiement extends CommonObject
|
||||
|
||||
// Verifier si paiement porte pas sur une facture classee
|
||||
// Si c'est le cas, on refuse la suppression
|
||||
$billsarray = $this->getBillsArray('fk_statut > 1');
|
||||
$billsarray = $this->getBillsArray('f.fk_statut > 1');
|
||||
if (is_array($billsarray)) {
|
||||
if (count($billsarray)) {
|
||||
$this->error = "ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible";
|
||||
|
||||
@ -168,6 +168,7 @@ abstract class CommonInvoice extends CommonObject
|
||||
|
||||
$discountstatic = new DiscountAbsolute($this->db);
|
||||
$result = $discountstatic->getSumDepositsUsed($this, $multicurrency);
|
||||
|
||||
if ($result >= 0) {
|
||||
return $result;
|
||||
} else {
|
||||
|
||||
@ -2104,7 +2104,7 @@ function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
|
||||
$langs->load("mails");
|
||||
|
||||
$sql2 = "SELECT m.rowid as id, m.titre as label, mc.date_envoi as dp, mc.date_envoi as dp2, '100' as percent, 'mailing' as type";
|
||||
$sql2 .= ", '' as fk_element, '' as elementtype, '' as contact_id";
|
||||
$sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
|
||||
$sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
|
||||
$sql2 .= ", u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname"; // User that valid action
|
||||
if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
|
||||
|
||||
@ -5396,7 +5396,7 @@ function price2num($amount, $rounding = '', $option = 0)
|
||||
} elseif ($rounding == 'MT') {
|
||||
$nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT;
|
||||
} elseif ($rounding == 'MS') {
|
||||
$nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK;
|
||||
$nbofdectoround = isset($conf->global->MAIN_MAX_DECIMALS_STOCK) ? $conf->global->MAIN_MAX_DECIMALS_STOCK : 5;
|
||||
} elseif ($rounding == 'CU') {
|
||||
$nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_UNIT, 8); // TODO Use param of currency
|
||||
} elseif ($rounding == 'CT') {
|
||||
@ -5404,6 +5404,7 @@ function price2num($amount, $rounding = '', $option = 0)
|
||||
} elseif (is_numeric($rounding)) {
|
||||
$nbofdectoround = (int) $rounding;
|
||||
}
|
||||
|
||||
//print " RR".$amount.' - '.$nbofdectoround.'<br>';
|
||||
if (dol_strlen($nbofdectoround)) {
|
||||
$amount = round(is_string($amount) ? (float) $amount : $amount, $nbofdectoround); // $nbofdectoround can be 0.
|
||||
|
||||
@ -2135,9 +2135,9 @@ function pdf_getlineprogress($object, $i, $outputlangs, $hidedetails = 0, $hookm
|
||||
return '';
|
||||
}
|
||||
if (empty($hidedetails) || $hidedetails > 1) {
|
||||
if ($conf->global->SITUATION_DISPLAY_DIFF_ON_PDF) {
|
||||
if (!empty($conf->global->SITUATION_DISPLAY_DIFF_ON_PDF)) {
|
||||
$prev_progress = 0;
|
||||
if (method_exists($object, 'get_prev_progress')) {
|
||||
if (method_exists($object->lines[$i], 'get_prev_progress')) {
|
||||
$prev_progress = $object->lines[$i]->get_prev_progress($object->id);
|
||||
}
|
||||
$result = round($object->lines[$i]->situation_percent - $prev_progress, 1).'%';
|
||||
|
||||
@ -269,6 +269,10 @@ function restrictedArea($user, $features, $objectid = 0, $tableandshare = '', $f
|
||||
if ($features == 'product') {
|
||||
$features = 'produit';
|
||||
}
|
||||
if ($features == 'banque') {
|
||||
$parentfortableentity = 'fk_account@bank_account';
|
||||
}
|
||||
|
||||
|
||||
// Get more permissions checks from hooks
|
||||
$parameters = array('features'=>$features, 'originalfeatures'=>$originalfeatures, 'objectid'=>$objectid, 'dbt_select'=>$dbt_select, 'idtype'=>$dbt_select, 'isdraft'=>$isdraft);
|
||||
|
||||
@ -2423,7 +2423,10 @@ if ($action == 'create') {
|
||||
$multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
|
||||
$multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
|
||||
$multicurrency_resteapayer = price2num($object->multicurrency_total_ttc - $multicurrency_totalpaye - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits, 'MT');
|
||||
$resteapayer = price2num($multicurrency_resteapayer / $object->multicurrency_tx, 'MT');
|
||||
// Code to fix case of corrupted data
|
||||
if ($resteapayer == 0 && $multicurrency_resteapayer != 0) {
|
||||
$resteapayer = price2num($multicurrency_resteapayer / $object->multicurrency_tx, 'MT');
|
||||
}
|
||||
}
|
||||
|
||||
if ($object->paye) {
|
||||
|
||||
@ -147,8 +147,11 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user u ON cp.fk_user = u.rowid";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_holiday_types ct ON cp.fk_type = ct.rowid";
|
||||
$sql .= " WHERE cp.rowid > 0";
|
||||
$sql .= " AND cp.statut = ".Holiday::STATUS_APPROVED;
|
||||
$sql .= " AND (date_format(cp.date_debut, '%Y-%m') = '".$db->escape($year_month)."' OR date_format(cp.date_fin, '%Y-%m') = '".$db->escape($year_month)."')";
|
||||
|
||||
$sql .= " AND (";
|
||||
$sql .= " (date_format(cp.date_debut, '%Y-%m') = '".$db->escape($year_month)."' OR date_format(cp.date_fin, '%Y-%m') = '".$db->escape($year_month)."')";
|
||||
$sql .= " OR"; // For leave over several months
|
||||
$sql .= " (date_format(cp.date_debut, '%Y-%m') < '".$db->escape($year_month)."' AND date_format(cp.date_fin, '%Y-%m') > '".$db->escape($year_month)."') ";
|
||||
$sql .= " )";
|
||||
if (!empty($search_ref)) {
|
||||
$sql .= natural_search('cp.ref', $search_ref);
|
||||
}
|
||||
|
||||
@ -534,6 +534,9 @@ UPDATE llx_facturedet SET situation_percent = 100 WHERE situation_percent IS NUL
|
||||
--update llx_facture set paye = 1, fk_statut = 2 where rowid in (select rowid from tmp_invoice_deposit_mark_as_available);
|
||||
|
||||
|
||||
-- TODO We should fix multicurrency_amount that are empty into llx_societe_remise_except, but we can't because we don't know what is the rate
|
||||
-- We may retreive info fro minvoice line by using fk_facture_line or fk_facture_supplier_line
|
||||
-- select * from llx_societe_remise_except where multicurrency_amount_ht = 0 and amount_ht <> 0;
|
||||
|
||||
|
||||
-- Note to migrate from old counter aquarium to new one
|
||||
|
||||
@ -111,7 +111,7 @@ class Inventory extends CommonObject
|
||||
'fk_user_valid' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserValidation', 'visible'=>-2, 'enabled'=>1, 'position'=>512, 'csslist'=>'tdoverflowmax200'),
|
||||
'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
|
||||
|
||||
'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>4, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'default'=>0, 'index'=>1, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Validated', 2=>'Recorded', 9=>'Canceled'))
|
||||
'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>4, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'default'=>0, 'index'=>1, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Validated', 2=>'Closed', 9=>'Canceled'))
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@ -144,7 +144,7 @@ if ($snom) {
|
||||
$sql .= natural_search('s.nom', $snom);
|
||||
}
|
||||
if ($suser) {
|
||||
$sql .= natural_search('u.login', $suser);
|
||||
natural_search(array('u.lastname', 'u.firstname', 'u.login'), $suser);
|
||||
}
|
||||
if ($sttc) {
|
||||
$sql .= natural_search('cf.total_ttc', $sttc, 1);
|
||||
|
||||
@ -912,7 +912,14 @@ if ($action == 'create') {
|
||||
|
||||
// Reception lines
|
||||
$numAsked = 0;
|
||||
|
||||
/**
|
||||
* @var array $suffix2numAsked map HTTP query parameter suffixes (like '1_0') to line indices so that
|
||||
* extrafields from HTTP query can be assigned to the correct dispatch line
|
||||
*/
|
||||
$suffix2numAsked = array();
|
||||
$dispatchLines = array();
|
||||
|
||||
foreach ($_POST as $key => $value) {
|
||||
// If create form is coming from the button "Create Reception" of previous page
|
||||
|
||||
@ -920,55 +927,70 @@ if ($action == 'create') {
|
||||
$reg = array();
|
||||
if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
|
||||
$numAsked++;
|
||||
$paramSuffix = $reg[1] . '_' . $reg[2];
|
||||
$suffix2numAsked[$paramSuffix] = $numAsked;
|
||||
|
||||
// $numline=$reg[2] + 1; // line of product
|
||||
$numline = $numAsked;
|
||||
$prod = "product_".$reg[1].'_'.$reg[2];
|
||||
$qty = "qty_".$reg[1].'_'.$reg[2];
|
||||
$ent = "entrepot_".$reg[1].'_'.$reg[2];
|
||||
$pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount
|
||||
$fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2];
|
||||
|
||||
$prod = "product_" . $paramSuffix;
|
||||
$qty = "qty_" . $paramSuffix;
|
||||
$ent = "entrepot_" . $paramSuffix;
|
||||
$pu = "pu_" . $paramSuffix; // This is unit price including discount
|
||||
$fk_commandefourndet = "fk_commandefourndet_" . $paramSuffix;
|
||||
$dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' => GETPOST($ent, 'int'), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' => GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'));
|
||||
}
|
||||
|
||||
// with batch module enabled
|
||||
if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
|
||||
$numAsked++;
|
||||
$paramSuffix = $reg[1] . '_' . $reg[2];
|
||||
$suffix2numAsked[$paramSuffix] = $numAsked;
|
||||
|
||||
// eat-by date dispatch
|
||||
// $numline=$reg[2] + 1; // line of product
|
||||
$numline = $numAsked;
|
||||
$prod = 'product_batch_'.$reg[1].'_'.$reg[2];
|
||||
$qty = 'qty_'.$reg[1].'_'.$reg[2];
|
||||
$ent = 'entrepot_'.$reg[1].'_'.$reg[2];
|
||||
$pu = 'pu_'.$reg[1].'_'.$reg[2];
|
||||
$lot = 'lot_number_'.$reg[1].'_'.$reg[2];
|
||||
$dDLUO = dol_mktime(12, 0, 0, GETPOST('dluo_'.$reg[1].'_'.$reg[2].'month', 'int'), GETPOST('dluo_'.$reg[1].'_'.$reg[2].'day', 'int'), GETPOST('dluo_'.$reg[1].'_'.$reg[2].'year', 'int'));
|
||||
$dDLC = dol_mktime(12, 0, 0, GETPOST('dlc_'.$reg[1].'_'.$reg[2].'month', 'int'), GETPOST('dlc_'.$reg[1].'_'.$reg[2].'day', 'int'), GETPOST('dlc_'.$reg[1].'_'.$reg[2].'year', 'int'));
|
||||
$fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2];
|
||||
|
||||
$prod = 'product_batch_' . $paramSuffix;
|
||||
$qty = 'qty_' . $paramSuffix;
|
||||
$ent = 'entrepot_' . $paramSuffix;
|
||||
$pu = 'pu_' . $paramSuffix;
|
||||
$lot = 'lot_number_' . $paramSuffix;
|
||||
$dDLUO = dol_mktime(12, 0, 0, $_POST['dluo_'.$paramSuffix.'month'], $_POST['dluo_'.$paramSuffix.'day'], $_POST['dluo_'.$paramSuffix.'year']);
|
||||
$dDLC = dol_mktime(12, 0, 0, $_POST['dlc_'.$paramSuffix.'month'], $_POST['dlc_'.$paramSuffix.'day'], $_POST['dlc_'.$paramSuffix.'year']);
|
||||
$fk_commandefourndet = 'fk_commandefourndet_'.$paramSuffix;
|
||||
$dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' =>GETPOST($ent, 'int'), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' =>GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'), 'DLC'=> $dDLC, 'DLUO'=> $dDLUO, 'lot'=> GETPOST($lot, 'alpha'));
|
||||
}
|
||||
|
||||
// If create form is coming from same page, it means that post was sent but an error occured
|
||||
if (preg_match('/^productid([0-9]+)$/i', $key, $reg)) {
|
||||
$numAsked++;
|
||||
$paramSuffix = $reg[1];
|
||||
$suffix2numAsked[$paramSuffix] = $numAsked;
|
||||
|
||||
// eat-by date dispatch
|
||||
// $numline=$reg[2] + 1; // line of product
|
||||
$numline = $numAsked;
|
||||
$prod = 'productid'.$reg[1];
|
||||
$comment = 'comment'.$reg[1];
|
||||
$qty = 'qtyl'.$reg[1];
|
||||
$ent = 'entl'.$reg[1];
|
||||
$pu = 'pul'.$reg[1];
|
||||
$lot = 'batch'.$reg[1];
|
||||
$dDLUO = dol_mktime(12, 0, 0, GETPOST('dluo'.$reg[1].'month', 'int'), GETPOST('dluo'.$reg[1].'day', 'int'), GETPOST('dluo'.$reg[1].'year', 'int'));
|
||||
$dDLC = dol_mktime(12, 0, 0, GETPOST('dlc'.$reg[1].'month', 'int'), GETPOST('dlc'.$reg[1].'day', 'int'), GETPOST('dlc'.$reg[1].'year', 'int'));
|
||||
$fk_commandefourndet = 'fk_commandefournisseurdet'.$reg[1];
|
||||
|
||||
$prod = 'productid'.$paramSuffix;
|
||||
$comment = 'comment'.$paramSuffix;
|
||||
$qty = 'qtyl'.$paramSuffix;
|
||||
$ent = 'entl'.$paramSuffix;
|
||||
$pu = 'pul'.$paramSuffix;
|
||||
$lot = 'batch'.$paramSuffix;
|
||||
$dDLUO = dol_mktime(12, 0, 0, GETPOST('dluo'.$paramSuffix.'month', 'int'), GETPOST('dluo'.$paramSuffix.'day', 'int'), GETPOST('dluo'.$paramSuffix.'year', 'int'));
|
||||
$dDLC = dol_mktime(12, 0, 0, GETPOST('dlc'.$paramSuffix.'month', 'int'), GETPOST('dlc'.$paramSuffix.'day', 'int'), GETPOST('dlc'.$paramSuffix.'year', 'int'));
|
||||
$fk_commandefourndet = 'fk_commandefournisseurdet'.$paramSuffix;
|
||||
$dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' =>GETPOST($ent, 'int'), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' =>GETPOST($comment), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'), 'DLC'=> $dDLC, 'DLUO'=> $dDLUO, 'lot'=> GETPOST($lot, 'alpha'));
|
||||
}
|
||||
}
|
||||
|
||||
// If extrafield values are passed in the HTTP query, assign them to the correct dispatch line
|
||||
// Note that if an extrafield with the same name exists in the origin supplier order line, the value
|
||||
// from the HTTP query will be ignored
|
||||
foreach ($suffix2numAsked as $suffix => $n) {
|
||||
$dispatchLines[$n]['array_options'] = $extrafields->getOptionalsFromPost('commande_fournisseur_dispatch', '_' . $suffix, '');
|
||||
}
|
||||
|
||||
print '<script type="text/javascript">
|
||||
jQuery(document).ready(function() {
|
||||
@ -1194,6 +1216,7 @@ if ($action == 'create') {
|
||||
}
|
||||
print "</tr>\n";
|
||||
|
||||
$extralabelslines = $extrafields->attributes[$line->table_element];
|
||||
//Display lines extrafields
|
||||
if (is_array($extralabelslines) && count($extralabelslines) > 0) {
|
||||
$colspan = 5;
|
||||
@ -1211,6 +1234,9 @@ if ($action == 'create') {
|
||||
$srcLine->fetch_optionals(); // fetch extrafields also available in orderline
|
||||
$line->fetch_optionals();
|
||||
|
||||
if (empty($line->array_options) && !empty($dispatchLines[$indiceAsked]['array_options'])) {
|
||||
$line->array_options = $dispatchLines[$indiceAsked]['array_options'];
|
||||
}
|
||||
$line->array_options = array_merge($line->array_options, $srcLine->array_options);
|
||||
|
||||
print $line->showOptionals($extrafields, 'edit', array('style'=>'class="oddeven"', 'colspan'=>$colspan), $indiceAsked);
|
||||
@ -1965,6 +1991,7 @@ if ($action == 'create') {
|
||||
print "</tr>";
|
||||
|
||||
// Display lines extrafields
|
||||
$extralabelslines = $extrafields->attributes[$lines[$i]->table_element];
|
||||
if (!empty($extralabelslines) && is_array($extralabelslines) && count($extralabelslines) > 0) {
|
||||
$colspan = empty($conf->productbatch->enabled) ? 8 : 9;
|
||||
$line = new CommandeFournisseurDispatch($db);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user