Beispiel #1
0
 /**
  *  \brief    	Update a line in database
  *  \param    	rowid            	Id of line to update
  *  \param    	desc             	Description de la ligne
  *  \param    	pu               	Prix unitaire
  *  \param    	qty              	Quantity
  *  \param    	remise_percent   	Pourcentage de remise de la ligne
  *  \param    	tva_tx           	Taux TVA
  * 	\param		txlocaltax1			Local tax 1 rate
  *  \param		txlocaltax2			Local tax 2 rate
  *  \param    	price_base_type		HT or TTC
  *  \param    	info_bits        	Miscellanous informations on line
  *  \param    	date_start        	Start date of the line
  *  \param    	date_end          	End date of the line
  * 	\param		type				Type of line (0=product, 1=service)
  *  \return   	int              	< 0 si erreur, > 0 si ok
  */
 function updateline($rowid, $desc, $pu, $qty, $remise_percent = 0, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type = 'HT', $info_bits = 0, $date_start = '', $date_end = '', $type = 0, $fk_parent_line = 0, $skip_update_total = 0)
 {
     global $conf;
     dol_syslog("CustomerOrder::UpdateLine {$rowid}, {$desc}, {$pu}, {$qty}, {$remise_percent}, {$txtva}, {$txlocaltax1}, {$txlocaltax2}, {$price_base_type}, {$info_bits}, {$date_start}, {$date_end}, {$type}");
     include_once DOL_DOCUMENT_ROOT . '/lib/price.lib.php';
     if ($this->brouillon) {
         $this->db->begin();
         // Clean parameters
         if (empty($qty)) {
             $qty = 0;
         }
         if (empty($info_bits)) {
             $info_bits = 0;
         }
         if (empty($txtva)) {
             $txtva = 0;
         }
         if (empty($txlocaltax1)) {
             $txlocaltax1 = 0;
         }
         if (empty($txlocaltax2)) {
             $txlocaltax2 = 0;
         }
         if (empty($remise)) {
             $remise = 0;
         }
         if (empty($remise_percent)) {
             $remise_percent = 0;
         }
         $remise_percent = price2num($remise_percent);
         $qty = price2num($qty);
         $pu = price2num($pu);
         $txtva = price2num($txtva);
         $txlocaltax1 = price2num($txtlocaltax1);
         $txlocaltax2 = price2num($txtlocaltax2);
         // Calcul du total TTC et de la TVA pour la ligne a partir de
         // qty, pu, remise_percent et txtva
         // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
         // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
         $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits);
         $total_ht = $tabprice[0];
         $total_tva = $tabprice[1];
         $total_ttc = $tabprice[2];
         $total_localtax1 = $tabprice[9];
         $total_localtax2 = $tabprice[10];
         // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser)
         $price = $pu;
         $subprice = $pu;
         $remise = 0;
         if ($remise_percent > 0) {
             $remise = round($pu * $remise_percent / 100, 2);
             $price = $pu - $remise;
         }
         // Update line
         $this->line = new OrderLine($this->db);
         // Stock previous line records
         $staticline = new OrderLine($this->db);
         $staticline->fetch($rowid);
         $this->line->oldline = $staticline;
         $this->line->rowid = $rowid;
         $this->line->desc = $desc;
         $this->line->qty = $qty;
         $this->line->tva_tx = $txtva;
         $this->line->localtax1_tx = $txlocaltax1;
         $this->line->localtax2_tx = $txlocaltax2;
         $this->line->remise_percent = $remise_percent;
         $this->line->subprice = $subprice;
         $this->line->info_bits = $info_bits;
         $this->line->total_ht = $total_ht;
         $this->line->total_tva = $total_tva;
         $this->line->total_localtax1 = $total_localtax1;
         $this->line->total_localtax2 = $total_localtax2;
         $this->line->total_ttc = $total_ttc;
         $this->line->date_start = $date_start;
         $this->line->date_end = $date_end;
         $this->line->product_type = $type;
         $this->line->fk_parent_line = $fk_parent_line;
         $this->line->skip_update_total = $skip_update_total;
         // TODO deprecated
         $this->line->price = $price;
         $this->line->remise = $remise;
         $result = $this->line->update();
         if ($result > 0) {
             // Mise a jour info denormalisees
             $this->update_price(1);
             $this->db->commit();
             return $result;
         } else {
             $this->error = $this->db->error();
             $this->db->rollback();
             dol_syslog("CustomerOrder::UpdateLine Error=" . $this->error, LOG_ERR);
             return -1;
         }
     } else {
         $this->error = "CustomerOrder::Updateline Order status makes operation forbidden";
         return -2;
     }
 }
Beispiel #2
0
 /**
  * Add a expedition line.
  * If STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS is set, you can add a shipment line, with no stock source defined
  * If STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT is not set, you can add a shipment line, even if not enough into stock
  *
  * @param 	int		$entrepot_id		Id of warehouse
  * @param 	int		$id					Id of source line (order line)
  * @param 	int		$qty				Quantity
  * @param	array		$array_options		extrafields array
  * @return	int							<0 if KO, >0 if OK
  */
 function addline($entrepot_id, $id, $qty, $array_options = 0)
 {
     global $conf, $langs;
     $num = count($this->lines);
     $line = new ExpeditionLigne($this->db);
     $line->entrepot_id = $entrepot_id;
     $line->origin_line_id = $id;
     $line->qty = $qty;
     $orderline = new OrderLine($this->db);
     $orderline->fetch($id);
     if (!empty($conf->stock->enabled) && !empty($orderline->fk_product)) {
         $fk_product = $orderline->fk_product;
         if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS)) {
             $langs->load("errors");
             $this->error = $langs->trans("ErrorWarehouseRequiredIntoShipmentLine");
             return -1;
         }
         if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) {
             // Check must be done for stock of product into warehouse if $entrepot_id defined
             $product = new Product($this->db);
             $result = $product->fetch($fk_product);
             $product_type = $product->type;
             if ($entrepot_id > 0) {
                 $product->load_stock();
                 $product_stock = $product->stock_warehouse[$entrepot_id]->real;
             } else {
                 $product_stock = $product->stock_reel;
             }
             if ($product_type == 0 && $product_stock < $qty) {
                 $this->error = $langs->trans('ErrorStockIsNotEnough');
                 $this->db->rollback();
                 return -3;
             }
         }
     }
     // extrafields
     if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) {
         // For avoid conflicts if trigger used
         $line->array_options = $array_options;
     }
     $this->lines[$num] = $line;
 }
Beispiel #3
0
 /**
  *  Update a line in database
  *
  *  @param    	int				$rowid            	Id of line to update
  *  @param    	string			$desc             	Description de la ligne
  *  @param    	float			$pu               	Prix unitaire
  *  @param    	float			$qty              	Quantity
  *  @param    	float			$remise_percent   	Pourcentage de remise de la ligne
  *  @param    	float			$txtva           	Taux TVA
  * 	@param		float			$txlocaltax1		Local tax 1 rate
  *  @param		float			$txlocaltax2		Local tax 2 rate
  *  @param    	string			$price_base_type	HT or TTC
  *  @param    	int				$info_bits        	Miscellaneous informations on line
  *  @param    	int		$date_start        	Start date of the line
  *  @param    	int		$date_end          	End date of the line
  * 	@param		int				$type				Type of line (0=product, 1=service)
  * 	@param		int				$fk_parent_line		Id of parent line (0 in most cases, used by modules adding sublevels into lines).
  * 	@param		int				$skip_update_total	Keep fields total_xxx to 0 (used for special lines by some modules)
  *  @param		int				$fk_fournprice		Id of origin supplier price
  *  @param		int				$pa_ht				Price (without tax) of product when it was bought
  *  @param		string			$label				Label
  *  @param		int				$special_code		Special code (also used by externals modules!)
  *  @param		array			$array_options		extrafields array
  * 	@param 		string			$fk_unit 			Code of the unit to use. Null to use the default one
  *  @return   	int              					< 0 if KO, > 0 if OK
  */
 function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $price_base_type = 'HT', $info_bits = 0, $date_start = '', $date_end = '', $type = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = null, $pa_ht = 0, $label = '', $special_code = 0, $array_options = 0, $fk_unit = null)
 {
     global $conf, $mysoc;
     dol_syslog(get_class($this) . "::updateline id={$rowid}, desc={$desc}, pu={$pu}, qty={$qty}, remise_percent={$remise_percent}, txtva={$txtva}, txlocaltax1={$txlocaltax1}, txlocaltax2={$txlocaltax2}, price_base_type={$price_base_type}, info_bits={$info_bits}, date_start={$date_start}, date_end={$date_end}, type={$type}, fk_parent_line={$fk_parent_line}, pa_ht={$pa_ht}, special_code={$special_code}");
     include_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php';
     if (!empty($this->brouillon)) {
         $this->db->begin();
         // Clean parameters
         if (empty($qty)) {
             $qty = 0;
         }
         if (empty($info_bits)) {
             $info_bits = 0;
         }
         if (empty($txtva)) {
             $txtva = 0;
         }
         if (empty($txlocaltax1)) {
             $txlocaltax1 = 0;
         }
         if (empty($txlocaltax2)) {
             $txlocaltax2 = 0;
         }
         if (empty($remise)) {
             $remise = 0;
         }
         if (empty($remise_percent)) {
             $remise_percent = 0;
         }
         if (empty($special_code) || $special_code == 3) {
             $special_code = 0;
         }
         $remise_percent = price2num($remise_percent);
         $qty = price2num($qty);
         $pu = price2num($pu);
         $pa_ht = price2num($pa_ht);
         $txtva = price2num($txtva);
         $txlocaltax1 = price2num($txlocaltax1);
         $txlocaltax2 = price2num($txlocaltax2);
         // Calcul du total TTC et de la TVA pour la ligne a partir de
         // qty, pu, remise_percent et txtva
         // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
         // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
         $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
         $txtva = preg_replace('/\\s*\\(.*\\)/', '', $txtva);
         // Remove code into vatrate.
         $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type);
         $total_ht = $tabprice[0];
         $total_tva = $tabprice[1];
         $total_ttc = $tabprice[2];
         $total_localtax1 = $tabprice[9];
         $total_localtax2 = $tabprice[10];
         // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser)
         $price = $pu;
         $subprice = $pu;
         $remise = 0;
         if ($remise_percent > 0) {
             $remise = round($pu * $remise_percent / 100, 2);
             $price = $pu - $remise;
         }
         //Fetch current line from the database and then clone the object and set it in $oldline property
         $line = new OrderLine($this->db);
         $line->fetch($rowid);
         $staticline = clone $line;
         $line->oldline = $staticline;
         $this->line = $line;
         $this->line->context = $this->context;
         // Reorder if fk_parent_line change
         if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
             $rangmax = $this->line_max($fk_parent_line);
             $this->line->rang = $rangmax + 1;
         }
         $this->line->rowid = $rowid;
         $this->line->label = $label;
         $this->line->desc = $desc;
         $this->line->qty = $qty;
         $this->line->tva_tx = $txtva;
         $this->line->localtax1_tx = $txlocaltax1;
         $this->line->localtax2_tx = $txlocaltax2;
         $this->line->localtax1_type = $localtaxes_type[0];
         $this->line->localtax2_type = $localtaxes_type[2];
         $this->line->remise_percent = $remise_percent;
         $this->line->subprice = $subprice;
         $this->line->info_bits = $info_bits;
         $this->line->special_code = $special_code;
         $this->line->total_ht = $total_ht;
         $this->line->total_tva = $total_tva;
         $this->line->total_localtax1 = $total_localtax1;
         $this->line->total_localtax2 = $total_localtax2;
         $this->line->total_ttc = $total_ttc;
         $this->line->date_start = $date_start;
         $this->line->date_end = $date_end;
         $this->line->product_type = $type;
         $this->line->fk_parent_line = $fk_parent_line;
         $this->line->skip_update_total = $skip_update_total;
         $this->line->fk_unit = $fk_unit;
         $this->line->fk_fournprice = $fk_fournprice;
         $this->line->pa_ht = $pa_ht;
         // TODO deprecated
         $this->line->price = $price;
         $this->line->remise = $remise;
         if (is_array($array_options) && count($array_options) > 0) {
             $this->line->array_options = $array_options;
         }
         $result = $this->line->update();
         if ($result > 0) {
             // Reorder if child line
             if (!empty($fk_parent_line)) {
                 $this->line_order(true, 'DESC');
             }
             // Mise a jour info denormalisees
             $this->update_price(1);
             $this->db->commit();
             return $result;
         } else {
             $this->error = $this->line->error;
             $this->db->rollback();
             return -1;
         }
     } else {
         $this->error = get_class($this) . "::updateline Order status makes operation forbidden";
         $this->errors = array('OrderStatusMakeOperationForbidden');
         return -2;
     }
 }
Beispiel #4
0
 /**
  * Add a expedition line.
  * If STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS is set, you can add a shipment line, with no stock source defined
  * If STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT is not set, you can add a shipment line, even if not enough into stock
  *
  * @param 	int		$entrepot_id		Id of warehouse
  * @param 	int		$id					Id of source line (order line)
  * @param 	int		$qty				Quantity
  * @return	int							<0 if KO, >0 if OK
  */
 function addline($entrepot_id, $id, $qty)
 {
     global $conf, $langs;
     $num = count($this->lines);
     $line = new ExpeditionLigne($this->db);
     $line->entrepot_id = $entrepot_id;
     $line->origin_line_id = $id;
     $line->qty = $qty;
     $orderline = new OrderLine($this->db);
     $orderline->fetch($id);
     if (!empty($conf->stock->enabled) && !empty($orderline->fk_product)) {
         $fk_product = $orderline->fk_product;
         if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS)) {
             $this->error = $langs->trans("ErrorWarehouseRequiredIntoShipmentLine");
             return -1;
         }
         if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) {
             $product = new Product($this->db);
             $result = $product->fetch($fk_product);
             $product_type = $product->type;
             if ($product_type == 0 && $product->stock_reel < $qty) {
                 $this->error = $langs->trans('ErrorStockIsNotEnough');
                 $this->db->rollback();
                 return -3;
             }
         }
     }
     $this->lines[$num] = $line;
 }
Beispiel #5
0
/**
 * Mise a jour des totaux lignes de commande
 *
 * @param	DoliDB		$db		Database handler
 * @param	Translate	$langs	Object langs
 * @param	Conf		$conf	Object conf
 * @return	void
 */
function migrate_price_commande($db, $langs, $conf)
{
    $db->begin();
    print '<tr><td colspan="4">';
    print '<br>';
    print '<b>' . $langs->trans('MigrationOrder') . "</b><br>\n";
    // Liste des lignes commande non a jour
    $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as tva_taux, cd.info_bits,";
    $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global";
    $sql .= " FROM " . MAIN_DB_PREFIX . "commandedet as cd, " . MAIN_DB_PREFIX . "commande as c";
    $sql .= " WHERE cd.fk_commande = c.rowid";
    $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
    dolibarr_install_syslog("upgrade2::migrate_price_commande", LOG_DEBUG);
    $resql = $db->query($sql);
    if ($resql) {
        $num = $db->num_rows($resql);
        $i = 0;
        if ($num) {
            while ($i < $num) {
                $obj = $db->fetch_object($resql);
                $rowid = $obj->rowid;
                $qty = $obj->qty;
                $pu = $obj->subprice;
                $txtva = $obj->tva_taux;
                $remise_percent = $obj->remise_percent;
                $remise_percent_global = $obj->remise_percent_global;
                $info_bits = $obj->info_bits;
                // On met a jour les 3 nouveaux champs
                $commandeligne = new OrderLine($db);
                $commandeligne->fetch($rowid);
                $result = calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, $remise_percent_global, 'HT', $info_bits, 0);
                $total_ht = $result[0];
                $total_tva = $result[1];
                $total_ttc = $result[2];
                $commandeligne->total_ht = $total_ht;
                $commandeligne->total_tva = $total_tva;
                $commandeligne->total_ttc = $total_ttc;
                dolibarr_install_syslog("upgrade2: Line {$rowid}: commandeid={$obj->rowid} pu={$pu} qty={$qty} tva_taux={$txtva} remise_percent={$remise_percent} remise_global={$remise_percent_global} -> {$total_ht}, {$total_tva}, {$total_ttc}");
                print ". ";
                $commandeligne->update_total();
                /* On touche pas a facture mere
                   $commande = new Commande($db);
                   $commande->id = $obj->rowid;
                   if ( $commande->fetch($commande->id) >= 0 )
                   {
                   if ( $commande->update_price() > 0 )
                   {
                   print ". ";
                   }
                   else
                   {
                   print "Error id=".$commande->id;
                   }
                   }
                   else
                   {
                   print "Error #3";
                   }
                   */
                $i++;
            }
        } else {
            print $langs->trans("AlreadyDone");
        }
        $db->free($resql);
        /*
        $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet";
        $sql.= " WHERE price = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0 AND remise_percent = 0";
        $resql=$db->query($sql);
        if (! $resql)
        {
        dol_print_error($db);
        }
        */
        $db->commit();
    } else {
        print "Error #1 " . $db->error();
        $db->rollback();
    }
    print '<br>';
    print '</td></tr>';
}
 /**
  * Add a expedition line
  *
  * @param 	int		$entrepot_id		Id of warehouse
  * @param 	int		$id					Id of source line
  * @param 	int		$qty				Quantity
  * @return	int							<0 if KO, >0 if OK
  */
 function addline($entrepot_id, $id, $qty)
 {
     global $conf, $langs;
     $num = count($this->lines);
     $line = new ExpeditionLigne($this->db);
     $line->entrepot_id = $entrepot_id;
     $line->origin_line_id = $id;
     $line->qty = $qty;
     if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) {
         $orderline = new OrderLine($this->db);
         $orderline->fetch($id);
         $fk_product = $orderline->fk_product;
         if (!empty($orderline->fk_product)) {
             $product = new Product($this->db);
             $result = $product->fetch($fk_product);
             $product_type = $product->type;
             if ($product_type == 0 && $product->stock_reel < $qty) {
                 $this->error = $langs->trans('ErrorStockIsNotEnough');
                 $this->db->rollback();
                 return -3;
             }
         }
     }
     $this->lines[$num] = $line;
 }