Fix load of segment prices not required for virtual stock change
virtual stock must include production (WIP)
This commit is contained in:
parent
f2ab3426ea
commit
12b4909c45
@ -44,7 +44,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
|
||||
// Load translation files required by the page
|
||||
$langs->loadLangs(array('bills', 'compta', 'admin', 'other', 'products'));
|
||||
$langs->loadLangs(array('bills', 'compta', 'admin', 'other', 'products', 'banks'));
|
||||
|
||||
$action = GETPOST('action', 'alpha');
|
||||
$massaction = GETPOST('massaction', 'alpha');
|
||||
@ -1030,6 +1030,8 @@ if ($action == 'create')
|
||||
// Only on template invoices
|
||||
$substitutionarray['__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $langs->trans("DateNextInvoiceBeforeGen").' ('.$langs->trans("Example").': '.dol_print_date($object->date_when, 'dayhour').')';
|
||||
$substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = $langs->trans("DateNextInvoiceAfterGen").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($object->date_when, $object->frequency, $object->unit_frequency), 'dayhour').')';
|
||||
$substitutionarray['__INVOICE_COUNTER_CURRENT__'] = $langs->trans("Count");
|
||||
$substitutionarray['__INVOICE_COUNTER_MAX__'] = $langs->trans("MaxPeriodNumber");
|
||||
|
||||
$htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
|
||||
foreach ($substitutionarray as $key => $val)
|
||||
@ -1446,8 +1448,6 @@ else
|
||||
print '</tr>';
|
||||
|
||||
// Bank Account
|
||||
$langs->load('banks');
|
||||
|
||||
print '<tr><td class="nowrap">';
|
||||
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
|
||||
print $langs->trans('BankAccount');
|
||||
@ -1468,8 +1468,6 @@ else
|
||||
print '</tr>';
|
||||
|
||||
// Model pdf
|
||||
$langs->load('banks');
|
||||
|
||||
print '<tr><td class="nowrap">';
|
||||
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
|
||||
print $langs->trans('Model');
|
||||
|
||||
@ -448,10 +448,12 @@ class Facture extends CommonInvoice
|
||||
$substitutionarray['__INVOICE_PREVIOUS_YEAR__'] = dol_print_date(dol_time_plus_duree($this->date, -1, 'y'), '%Y');
|
||||
$substitutionarray['__INVOICE_YEAR__'] = dol_print_date($this->date, '%Y');
|
||||
$substitutionarray['__INVOICE_NEXT_YEAR__'] = dol_print_date(dol_time_plus_duree($this->date, 1, 'y'), '%Y');
|
||||
// Only for tempalte invoice
|
||||
// Only for template invoice
|
||||
$substitutionarray['__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = dol_print_date($originaldatewhen, 'dayhour');
|
||||
$substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = dol_print_date($nextdatewhen, 'dayhour');
|
||||
$substitutionarray['__INVOICE_PREVIOUS_DATE_NEXT_INVOICE_AFTER_GEN__'] = dol_print_date($previousdaynextdatewhen, 'dayhour');
|
||||
$substitutionarray['__INVOICE_COUNTER_CURRENT__'] = $_facrec->nb_gen_done;
|
||||
$substitutionarray['__INVOICE_COUNTER_MAX__'] = $_facrec->nb_gen_max;
|
||||
|
||||
//var_dump($substitutionarray);exit;
|
||||
|
||||
|
||||
@ -2364,6 +2364,7 @@ class Form
|
||||
$objp->price_ttc = price2num($objp->price_ttc, 'MU');
|
||||
}
|
||||
}
|
||||
|
||||
$this->constructProductListOption($objp, $opt, $optJson, $price_level, $selected, $hidepriceinlabel, $filterkey);
|
||||
// Add new entry
|
||||
// "key" value of json key array is used by jQuery automatically as selected value
|
||||
@ -2514,7 +2515,7 @@ class Form
|
||||
$sql .= " ORDER BY date_price DESC, rowid DESC"; // Warning DESC must be both on date_price and rowid.
|
||||
$sql .= " LIMIT 1";
|
||||
|
||||
dol_syslog(get_class($this).'::constructProductListOption search price for level '.$price_level.'', LOG_DEBUG);
|
||||
dol_syslog(get_class($this).'::constructProductListOption search price for product '.$objp->rowid.' AND level '.$price_level.'', LOG_DEBUG);
|
||||
$result2 = $this->db->query($sql);
|
||||
if ($result2)
|
||||
{
|
||||
@ -2642,7 +2643,7 @@ class Form
|
||||
$langs->load("stocks");
|
||||
|
||||
$tmpproduct = new Product($this->db);
|
||||
$tmpproduct->fetch($objp->rowid);
|
||||
$tmpproduct->fetch($objp->rowid, '', '', '', 1, 1, 1); // Load product without lang and prices arrays (we just need to make ->virtual_stock() after)
|
||||
$tmpproduct->load_virtual_stock();
|
||||
$virtualstock = $tmpproduct->stock_theorique;
|
||||
|
||||
|
||||
@ -2051,9 +2051,11 @@ class Product extends CommonObject
|
||||
* @param string $ref_ext Ref ext of product/service to load
|
||||
* @param string $barcode Barcode of product/service to load
|
||||
* @param int $ignore_expression Ignores the math expression for calculating price and uses the db value instead
|
||||
* @return int <0 if KO, 0 if not found, >0 if OK
|
||||
* @param int $ignore_price_load Load product without loading prices arrays (when we are sure we don't need them)
|
||||
* @param int $ignore_lang_load Load product without loading language arrays (when we are sure we don't need them)
|
||||
* @return int <0 if KO, 0 if not found, >0 if OK
|
||||
*/
|
||||
public function fetch($id = '', $ref = '', $ref_ext = '', $barcode = '', $ignore_expression = 0)
|
||||
public function fetch($id = '', $ref = '', $ref_ext = '', $barcode = '', $ignore_expression = 0, $ignore_price_load = 0, $ignore_lang_load = 0)
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
|
||||
@ -2182,12 +2184,12 @@ class Product extends CommonObject
|
||||
$this->fetch_optionals();
|
||||
|
||||
// multilangs
|
||||
if (!empty($conf->global->MAIN_MULTILANGS)) {
|
||||
if (!empty($conf->global->MAIN_MULTILANGS) && empty($ignore_lang_load)) {
|
||||
$this->getMultiLangs();
|
||||
}
|
||||
|
||||
// Load multiprices array
|
||||
if (!empty($conf->global->PRODUIT_MULTIPRICES)) // prices per segment
|
||||
if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($ignore_price_load)) // prices per segment
|
||||
{
|
||||
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
|
||||
{
|
||||
@ -2255,11 +2257,11 @@ class Product extends CommonObject
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) // prices per customers
|
||||
elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && empty($ignore_price_load)) // prices per customers
|
||||
{
|
||||
// Nothing loaded by default. List may be very long.
|
||||
}
|
||||
elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) // prices per quantity
|
||||
elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) && empty($ignore_price_load)) // prices per quantity
|
||||
{
|
||||
$sql = "SELECT price, price_ttc, price_min, price_min_ttc,";
|
||||
$sql .= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid";
|
||||
@ -2310,7 +2312,7 @@ class Product extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) // prices per customer and quantity
|
||||
elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES) && empty($ignore_price_load)) // prices per customer and quantity
|
||||
{
|
||||
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
|
||||
{
|
||||
@ -2770,7 +2772,7 @@ class Product extends CommonObject
|
||||
// phpcs:enable
|
||||
global $conf, $user;
|
||||
|
||||
$sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
|
||||
$sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_suppliers, COUNT(DISTINCT cf.rowid) as nb,";
|
||||
$sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
|
||||
@ -2791,7 +2793,7 @@ class Product extends CommonObject
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
$obj = $this->db->fetch_object($result);
|
||||
$this->stats_reception['suppliers'] = $obj->nb_customers;
|
||||
$this->stats_reception['suppliers'] = $obj->nb_suppliers;
|
||||
$this->stats_reception['nb'] = $obj->nb;
|
||||
$this->stats_reception['rows'] = $obj->nb_rows;
|
||||
$this->stats_reception['qty'] = $obj->qty ? $obj->qty : 0;
|
||||
@ -4674,6 +4676,7 @@ class Product extends CommonObject
|
||||
$stock_commande_fournisseur = 0;
|
||||
$stock_sending_client = 0;
|
||||
$stock_reception_fournisseur = 0;
|
||||
$stock_inproduction = 0;
|
||||
|
||||
if (!empty($conf->commande->enabled))
|
||||
{
|
||||
@ -4699,34 +4702,49 @@ class Product extends CommonObject
|
||||
$result = $this->load_stats_commande_fournisseur(0, '1,2,3,4', 1);
|
||||
if ($result < 0) dol_print_error($this->db, $this->error);
|
||||
$stock_commande_fournisseur = $this->stats_commande_fournisseur['qty'];
|
||||
|
||||
}
|
||||
if (!empty($conf->fournisseur->enabled) && empty($conf->reception->enabled))
|
||||
{
|
||||
$result = $this->load_stats_reception(0, '4', 1);
|
||||
if ($result < 0) dol_print_error($this->db, $this->error);
|
||||
$stock_reception_fournisseur = $this->stats_reception['qty'];
|
||||
}
|
||||
if (!empty($conf->fournisseur->enabled) && !empty($conf->reception->enabled))
|
||||
{
|
||||
$result = $this->load_stats_reception(0, '4', 1); // Use same tables than when module reception is not used.
|
||||
if ($result < 0) dol_print_error($this->db, $this->error);
|
||||
$stock_reception_fournisseur = $this->stats_reception['qty'];
|
||||
}
|
||||
if (!empty($conf->mrp->enabled))
|
||||
{
|
||||
// TODO
|
||||
$stock_inproduction = 0;
|
||||
}
|
||||
|
||||
$this->stock_theorique = $this->stock_reel + $stock_inproduction;
|
||||
|
||||
// Stock decrease mode
|
||||
if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
|
||||
$this->stock_theorique = $this->stock_reel - $stock_commande_client + $stock_sending_client;
|
||||
$this->stock_theorique -= ($stock_commande_client - $stock_sending_client);
|
||||
}
|
||||
if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)) {
|
||||
$this->stock_theorique = $this->stock_reel;
|
||||
elseif (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)) {
|
||||
$this->stock_theorique += 0;
|
||||
}
|
||||
if (!empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
|
||||
$this->stock_theorique = $this->stock_reel - $stock_commande_client;
|
||||
elseif (!empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
|
||||
$this->stock_theorique -= $stock_commande_client;
|
||||
}
|
||||
// Stock Increase mode
|
||||
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
|
||||
$this->stock_theorique += $stock_commande_fournisseur - $stock_reception_fournisseur;
|
||||
$this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
|
||||
}
|
||||
if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
|
||||
$this->stock_theorique += $stock_commande_fournisseur - $stock_reception_fournisseur;
|
||||
elseif (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
|
||||
$this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
|
||||
}
|
||||
if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) {
|
||||
elseif (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) {
|
||||
$this->stock_theorique -= $stock_reception_fournisseur;
|
||||
}
|
||||
if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) {
|
||||
$this->stock_theorique += $stock_commande_fournisseur - $stock_reception_fournisseur;
|
||||
elseif (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) {
|
||||
$this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
|
||||
}
|
||||
|
||||
if (!is_object($hookmanager)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user