Merge branch stock_decrease_on_credit_invoice
This commit is contained in:
parent
2caf002fa0
commit
c06fef0d45
@ -222,6 +222,26 @@ if (!empty($conf->facture->enabled)) {
|
||||
print "</td>\n</tr>\n";
|
||||
$found++;
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->trans("DeStockOnCreditBill").'</td>';
|
||||
print '<td class="right">';
|
||||
if (!empty($conf->facture->enabled))
|
||||
{
|
||||
if ($conf->use_javascript_ajax) {
|
||||
print ajax_constantonoff('STOCK_CALCULATE_ON_CREDIT_BILL');
|
||||
} else {
|
||||
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
|
||||
print $form->selectarray("STOCK_CALCULATE_ON_CREDIT_BILL", $arrval, $conf->global->STOCK_CALCULATE_ON_CREDIT_BILL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module30Name"));
|
||||
}
|
||||
print "</td>\n</tr>\n";
|
||||
$found++;
|
||||
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->trans("DeStockOnValidateOrder").'</td>';
|
||||
|
||||
@ -912,7 +912,7 @@ if ($resql) {
|
||||
print $langs->trans('ValidateInvoices');
|
||||
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) || !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL) ) ) {
|
||||
print $form->selectyesno('validate_invoices', 0, 1, 1);
|
||||
print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
|
||||
} else {
|
||||
|
||||
@ -627,7 +627,7 @@ if (empty($reshook)) {
|
||||
}
|
||||
|
||||
// Check for warehouse
|
||||
if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
|
||||
if ( ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) ) {
|
||||
$qualified_for_stock_change = 0;
|
||||
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
|
||||
$qualified_for_stock_change = $object->hasProductsOrServices(2);
|
||||
@ -687,7 +687,7 @@ if (empty($reshook)) {
|
||||
$object->fetch_thirdparty();
|
||||
|
||||
// Check parameters
|
||||
if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
|
||||
if ( ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) ) {
|
||||
$qualified_for_stock_change = 0;
|
||||
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
|
||||
$qualified_for_stock_change = $object->hasProductsOrServices(2);
|
||||
@ -3894,7 +3894,12 @@ if ($action == 'create') {
|
||||
$text = $langs->trans('ConfirmDeleteBill', $object->ref);
|
||||
$formquestion = array();
|
||||
|
||||
if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->statut >= 1) {
|
||||
if ($object->statut >= 1 &&
|
||||
(
|
||||
($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) ||
|
||||
($object->type == Facture::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL))
|
||||
)
|
||||
) {
|
||||
$qualified_for_stock_change = 0;
|
||||
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
|
||||
$qualified_for_stock_change = $object->hasProductsOrServices(2);
|
||||
@ -3967,7 +3972,7 @@ if ($action == 'create') {
|
||||
}
|
||||
$formquestion = array();
|
||||
|
||||
if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
|
||||
if ( ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) ) {
|
||||
$qualified_for_stock_change = 0;
|
||||
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
|
||||
$qualified_for_stock_change = $object->hasProductsOrServices(2);
|
||||
@ -4009,7 +4014,7 @@ if ($action == 'create') {
|
||||
$text = $langs->trans('ConfirmUnvalidateBill', $object->ref);
|
||||
$formquestion = array();
|
||||
|
||||
if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
|
||||
if (($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) || ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) ) {
|
||||
$qualified_for_stock_change = 0;
|
||||
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
|
||||
$qualified_for_stock_change = $object->hasProductsOrServices(2);
|
||||
|
||||
@ -2273,7 +2273,12 @@ class Facture extends CommonInvoice
|
||||
}
|
||||
|
||||
// If we decrease stock on invoice validation, we increase back if a warehouse id was provided
|
||||
if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $idwarehouse != -1) {
|
||||
if ( $result >= 0 && !empty($conf->stock->enabled) && $idwarehouse != -1 &&
|
||||
(
|
||||
($this->type != self::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) ||
|
||||
($this->type == self::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL))
|
||||
)
|
||||
) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
|
||||
$langs->load("agenda");
|
||||
|
||||
@ -2712,7 +2717,12 @@ class Facture extends CommonInvoice
|
||||
$result = $this->thirdparty->set_as_client();
|
||||
|
||||
// Si active on decremente le produit principal et ses composants a la validation de facture
|
||||
if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $idwarehouse > 0) {
|
||||
if ( $result >= 0 && !empty($conf->stock->enabled) && $idwarehouse > 0 &&
|
||||
(
|
||||
($this->type != self::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) ||
|
||||
($this->type == self::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL))
|
||||
)
|
||||
) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
|
||||
$langs->load("agenda");
|
||||
|
||||
@ -3005,7 +3015,12 @@ class Facture extends CommonInvoice
|
||||
}
|
||||
|
||||
// If we decrease stock on invoice validation, we increase back
|
||||
if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
|
||||
if ( $result >= 0 && !empty($conf->stock->enabled) &&
|
||||
(
|
||||
($this->type != self::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) ||
|
||||
($this->type == self::TYPE_CREDIT_NOTE && !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL))
|
||||
)
|
||||
) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
|
||||
$langs->load("agenda");
|
||||
|
||||
|
||||
@ -1199,7 +1199,12 @@ if ($action == 'remove_file') {
|
||||
if (!$error && $massaction == 'validate' && $permissiontoadd) {
|
||||
$objecttmp = new $objectclass($db);
|
||||
|
||||
if (($objecttmp->element == 'facture' || $objecttmp->element == 'invoice') && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
|
||||
if ( !empty($conf->stock->enabled) && ($objecttmp->element == 'facture' || $objecttmp->element == 'invoice') &&
|
||||
(
|
||||
!empty($conf->global->STOCK_CALCULATE_ON_BILL) ||
|
||||
!empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)
|
||||
)
|
||||
) {
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans('ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null, 'errors');
|
||||
$error++;
|
||||
|
||||
@ -531,6 +531,8 @@ class Conf
|
||||
|
||||
if (!empty($this->productbatch->enabled)) {
|
||||
$this->global->STOCK_CALCULATE_ON_BILL = 0;
|
||||
$this->global->STOCK_CALCULATE_ON_INVOICE_BILL = 0;
|
||||
$this->global->STOCK_CALCULATE_ON_CREDIT_BILL = 0;
|
||||
$this->global->STOCK_CALCULATE_ON_VALIDATE_ORDER = 0;
|
||||
$this->global->STOCK_CALCULATE_ON_SHIPMENT = 1;
|
||||
$this->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE = 0;
|
||||
|
||||
@ -75,6 +75,7 @@ OrderDispatch=Item receipts
|
||||
RuleForStockManagementDecrease=Choose Rule for automatic stock decrease (manual decrease is always possible, even if an automatic decrease rule is activated)
|
||||
RuleForStockManagementIncrease=Choose Rule for automatic stock increase (manual increase is always possible, even if an automatic increase rule is activated)
|
||||
DeStockOnBill=Decrease real stocks on validation of customer invoice/credit note
|
||||
DeStockOnCreditBill=Decrease (increase) real stocks on validation of customer credit (only) note
|
||||
DeStockOnValidateOrder=Decrease real stocks on validation of sales order
|
||||
DeStockOnShipment=Decrease real stocks on shipping validation
|
||||
DeStockOnShipmentOnClosing=Decrease real stocks when shipping is set to closed
|
||||
|
||||
@ -75,6 +75,7 @@ OrderDispatch=Réceptions
|
||||
RuleForStockManagementDecrease=Règle de gestion des décrémentations automatiques de stock (la décrémentation manuelle est toujours possible, même si une décrémentation automatique est activée)
|
||||
RuleForStockManagementIncrease=Règle de gestion des incrémentations de stock (l'incrémentation manuelle est toujours possible, même si une incrémentation automatique est activée)
|
||||
DeStockOnBill=Décrémenter les stocks physiques sur validation des factures/avoirs clients
|
||||
DeStockOnCreditBill=Décrémenter (incrémenter) les stocks physiques sur validation des avoirs (uniquement) clients
|
||||
DeStockOnValidateOrder=Décrémenterr les stocks physiques sur validation des commandes clients
|
||||
DeStockOnShipment=Décrémenter les stocks physiques sur validation des expéditions
|
||||
DeStockOnShipmentOnClosing=Décrémente les stocks physiques au classement "clôturée" de l'expédition
|
||||
|
||||
@ -2949,14 +2949,19 @@ 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 b invoice validation.
|
||||
// If option DECREASE_ONLY_UNINVOICEDPRODUCTS is on, we make a compensation.
|
||||
if (!empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
|
||||
if (!empty($conf->global->STOCK_CALCULATE_ON_BILL) || !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL) ) {
|
||||
if (!empty($conf->global->DECREASE_ONLY_UNINVOICEDPRODUCTS)) {
|
||||
$adeduire = 0;
|
||||
$sql = "SELECT sum(fd.qty) as count FROM ".MAIN_DB_PREFIX."facturedet fd ";
|
||||
$sql .= " JOIN ".MAIN_DB_PREFIX."facture f ON fd.fk_facture = f.rowid ";
|
||||
$sql .= " JOIN ".MAIN_DB_PREFIX."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'";
|
||||
$sql .= " JOIN ".MAIN_DB_PREFIX."commande 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);
|
||||
|
||||
if(!empty($conf->global->STOCK_CALCULATE_ON_BILL)){
|
||||
$sql .= " WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).") AND c.facture = 0 AND fd.fk_product = ".((int) $this->id);
|
||||
}else if(!empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)){
|
||||
$sql .= " WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).") AND c.facture = 0 AND fd.fk_product = ".((int) $this->id)." AND f.type = ".Facture::TYPE_CREDIT_NOTE;
|
||||
}
|
||||
dol_syslog(__METHOD__.":: sql $sql", LOG_NOTICE);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
@ -5306,11 +5311,16 @@ class Product extends CommonObject
|
||||
// Stock decrease mode
|
||||
if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
|
||||
$this->stock_theorique -= ($stock_commande_client - $stock_sending_client);
|
||||
} elseif (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)) {
|
||||
if(!empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) { // this is not exclusive with STOCK_CALCULATE_ON_SHIPMENT(_CLOSE)
|
||||
$this->stock_theorique -= $stock_commande_client;
|
||||
}
|
||||
|
||||
}elseif (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)) {
|
||||
$this->stock_theorique += 0;
|
||||
} elseif (!empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
|
||||
}elseif (!empty($conf->global->STOCK_CALCULATE_ON_BILL) || !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_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);
|
||||
|
||||
@ -724,6 +724,7 @@ if ($id > 0 || $ref) {
|
||||
$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_BILL) ? '- '.$langs->trans("DeStockOnBill").'<br>' : '');
|
||||
$text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL) ? '- '.$langs->trans("DeStockOnCreditBill").'<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_DISPATCH_ORDER) ? '- '.$langs->trans("ReStockOnDispatchOrder").'<br>' : '');
|
||||
|
||||
@ -644,7 +644,7 @@ if ($massaction == 'createbills') {
|
||||
print $langs->trans('ValidateInvoices');
|
||||
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) || !empty($conf->global->STOCK_CALCULATE_ON_CREDIT_BILL)) ) {
|
||||
print $form->selectyesno('validate_invoices', 0, 1, 1);
|
||||
print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user