diff --git a/htdocs/accountancy/admin/index.php b/htdocs/accountancy/admin/index.php index 385c105451e..244b6f72330 100644 --- a/htdocs/accountancy/admin/index.php +++ b/htdocs/accountancy/admin/index.php @@ -430,7 +430,7 @@ foreach ($list_binding as $key) { print $form->selectDate((!empty($conf->global->$key) ? $db->idate($conf->global->$key) : -1), $key, 0, 0, 1); } elseif ($key == 'ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER') { $array = array(0=>$langs->trans("PreviousMonth"), 1=>$langs->trans("CurrentMonth"), 2=>$langs->trans("Fiscalyear")); - print $form->selectarray($key, $array, (isset($conf->global->ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER) ? $conf->global->ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER : 0)); + print $form->selectarray($key, $array, (isset($conf->global->ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER) ? $conf->global->ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER : 0), 0, 0, 0, '', 0, 0, 0, '', 'onrightofpage'); } else { print ''; } diff --git a/htdocs/compta/resultat/result.php b/htdocs/compta/resultat/result.php index 07a82fc92ac..e92b41c787c 100644 --- a/htdocs/compta/resultat/result.php +++ b/htdocs/compta/resultat/result.php @@ -339,60 +339,81 @@ if ($modecompta == 'CREANCES-DETTES') { } $result = strtr($formula, $vars); + $result = str_replace('--', '+', $result); - //var_dump($result); - //$r = $AccCat->calculate($result); - $r = dol_eval($result, 1, 1, '1'); - //var_dump($r); - - print ''.price($r).''; - - // Year N - $code = $cat['code']; // code of categorie ('VTE', 'MAR', ...) - $sommes[$code]['NP'] += $r; - - // Current fiscal year (N) - if (is_array($sommes) && !empty($sommes)) { - foreach ($sommes as $code => $det) { - $vars[$code] = $det['N']; - } - } - - $result = strtr($formula, $vars); - - //$r = $AccCat->calculate($result); - $r = dol_eval($result, 1, 1, 1); - - print ''.price($r).''; - $sommes[$code]['N'] += $r; - - // Detail by month - foreach ($months as $k => $v) { - if (($k + 1) >= $date_startmonth) { - foreach ($sommes as $code => $det) { - $vars[$code] = $det['M'][$k]; + if (preg_match('/[a-z]/i', $result)) { + $r = 'Error bad formula: '.$result; + $rshort = 'Err'; + print ''.$rshort.''; + print ''.$rshort.''; + // Detail by month + foreach ($months as $k => $v) { + if (($k + 1) >= $date_startmonth) { + print ''.$rshort.''; } - $result = strtr($formula, $vars); - - //$r = $AccCat->calculate($result); - $r = dol_eval($result, 1, 1, 1); - - print ''.price($r).''; - $sommes[$code]['M'][$k] += $r; } - } - foreach ($months as $k => $v) { - if (($k + 1) < $date_startmonth) { - foreach ($sommes as $code => $det) { - $vars[$code] = $det['M'][$k]; + foreach ($months as $k => $v) { + if (($k + 1) < $date_startmonth) { + print ''.$rshort.''; } - $result = strtr($formula, $vars); + } + } else { + //var_dump($result); + //$r = $AccCat->calculate($result); + $r = dol_eval($result, 1, 1, '1'); + //var_dump($r); - //$r = $AccCat->calculate($result); - $r = dol_eval($result, 1, 1, 1); + print ''.price($r).''; - print ''.price($r).''; - $sommes[$code]['M'][$k] += $r; + // Year N + $code = $cat['code']; // code of categorie ('VTE', 'MAR', ...) + $sommes[$code]['NP'] += $r; + + // Current fiscal year (N) + if (is_array($sommes) && !empty($sommes)) { + foreach ($sommes as $code => $det) { + $vars[$code] = $det['N']; + } + } + + $result = strtr($formula, $vars); + + //$r = $AccCat->calculate($result); + $r = dol_eval($result, 1, 1, 1); + + print ''.price($r).''; + $sommes[$code]['N'] += $r; + + // Detail by month + foreach ($months as $k => $v) { + if (($k + 1) >= $date_startmonth) { + foreach ($sommes as $code => $det) { + $vars[$code] = $det['M'][$k]; + } + $result = strtr($formula, $vars); + + //$r = $AccCat->calculate($result); + $r = dol_eval($result, 1, 1, 1); + + print ''.price($r).''; + $sommes[$code]['M'][$k] += $r; + } + } + + + foreach ($months as $k => $v) { + if (($k + 1) < $date_startmonth) { + foreach ($sommes as $code => $det) { + $vars[$code] = $det['M'][$k]; + } + $result = strtr($formula, $vars); + + //$r = $AccCat->calculate($result); + $r = dol_eval($result, 1, 1, 1); + + print ''.price($r).''; + $sommes[$code]['M'][$k] += $r; + } } } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index f0e8bae274b..7db7ec1ba96 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3005,7 +3005,7 @@ class Product extends CommonObject * * @param int $socid Id societe pour filtrer sur une societe * @param string $filtrestatut Id statut pour filtrer sur un statut - * @param int $forVirtualStock Ignore rights filter for virtual stock calculation. + * @param int $forVirtualStock Ignore rights filter for virtual stock calculation. Set when load_stats_commande is used for virtual stock calculation. * @return integer Array of stats in $this->stats_commande (nb=nb of order, qty=qty ordered), <0 if ko or >0 if ok */ public function load_stats_commande($socid = 0, $filtrestatut = '', $forVirtualStock = 0) @@ -3066,17 +3066,37 @@ class Product extends CommonObject // If stock decrease is on invoice validation, the theorical stock continue to // count the orders to ship in theorical stock when some are already removed by invoice validation. - // If option DECREASE_ONLY_UNINVOICEDPRODUCTS is on, we make a compensation. - if (!empty($conf->global->STOCK_CALCULATE_ON_BILL)) { + if ($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) { if (!empty($conf->global->DECREASE_ONLY_UNINVOICEDPRODUCTS)) { + // If option DECREASE_ONLY_UNINVOICEDPRODUCTS is on, we make a compensation but only if order not yet invoice. $adeduire = 0; - $sql = "SELECT sum(fd.qty) as count FROM ".$this->db->prefix()."facturedet fd "; - $sql .= " JOIN ".$this->db->prefix()."facture f ON fd.fk_facture = f.rowid "; - $sql .= " JOIN ".$this->db->prefix()."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'"; - $sql .= " JOIN ".$this->db->prefix()."commande c ON el.fk_source = c.rowid "; + $sql = "SELECT sum(fd.qty) as count FROM ".$this->db->prefix()."facturedet as fd "; + $sql .= " JOIN ".$this->db->prefix()."facture as f ON fd.fk_facture = f.rowid "; + $sql .= " JOIN ".$this->db->prefix()."element_element as el ON ((el.fk_target = f.rowid AND el.targettype = 'facture' AND sourcetype = 'commande') OR (el.fk_source = f.rowid AND el.targettype = 'commande' AND sourcetype = 'facture'))"; + $sql .= " JOIN ".$this->db->prefix()."commande as c ON el.fk_source = c.rowid "; $sql .= " WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).") AND c.facture = 0 AND fd.fk_product = ".((int) $this->id); dol_syslog(__METHOD__.":: sql $sql", LOG_NOTICE); + $resql = $this->db->query($sql); + if ($resql) { + if ($this->db->num_rows($resql) > 0) { + $obj = $this->db->fetch_object($resql); + $adeduire += $obj->count; + } + } + $this->stats_commande['qty'] -= $adeduire; + } else { + // If option DECREASE_ONLY_UNINVOICEDPRODUCTS is off, we make a compensation with lines of invoices linked to the order + include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + + // For every order having invoice already validated we need to decrease stock cause it's in physical stock + $adeduire = 0; + $sql = 'SELECT sum(fd.qty) as count FROM '.MAIN_DB_PREFIX.'facturedet as fd '; + $sql .= ' JOIN '.MAIN_DB_PREFIX.'facture as f ON fd.fk_facture = f.rowid '; + $sql .= ' JOIN '.MAIN_DB_PREFIX."element_element as el ON ((el.fk_target = f.rowid AND el.targettype = 'facture' AND sourcetype = 'commande') OR (el.fk_source = f.rowid AND el.targettype = 'commande' AND sourcetype = 'facture'))"; + $sql .= ' JOIN '.MAIN_DB_PREFIX.'commande as c ON el.fk_source = c.rowid '; + $sql .= ' WHERE c.fk_statut IN ('.$this->db->sanitize($filtrestatut).') AND f.fk_statut > '.Facture::STATUS_DRAFT.' AND fd.fk_product = '.((int) $this->id); + dol_syslog(__METHOD__.":: sql $sql", LOG_NOTICE); $resql = $this->db->query($sql); if ($resql) { if ($this->db->num_rows($resql) > 0) {