Beispiel #1
0
 $extrafieldsline = new ExtraFields($db);
 $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
 $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
 // Unset extrafield
 if (is_array($extralabelsline)) {
     // Get extra fields
     foreach ($extralabelsline as $key => $value) {
         unset($_POST["options_" . $key]);
     }
 }
 // Define special_code for special lines
 $special_code = GETPOST('special_code');
 if (!GETPOST('qty')) {
     $special_code = 3;
 }
 $line = new FactureLigne($db);
 $line->fetch(GETPOST('lineid'));
 $percent = $line->get_prev_progress();
 if (GETPOST('progress') < $percent) {
     $mesg = '<div class="warning">' . $langs->trans("CantBeLessThanMinPercent") . '</div>';
     setEventMessages($mesg, null, 'warnings');
     $error++;
     $result = -1;
 }
 // Check minimum price
 $productid = GETPOST('productid', 'int');
 if (!empty($productid)) {
     $product = new Product($db);
     $product->fetch($productid);
     $type = $product->type;
     $price_min = $product->price_min;
Beispiel #2
0
 $obj = $db->fetch_object($result);
 // les variables
 $cptcli = !empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef");
 $compta_soc = !empty($obj->code_compta) ? $obj->code_compta : $cptcli;
 $compta_prod = $obj->compte;
 if (empty($compta_prod)) {
     if ($obj->product_type == 0) {
         $compta_prod = !empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef");
     } else {
         $compta_prod = !empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef");
     }
 }
 $cpttva = !empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT : $langs->trans("CodeNotDef");
 $compta_tva = !empty($obj->account_tva) ? $obj->account_tva : $cpttva;
 // Situation invoices handling
 $line = new FactureLigne($db);
 $line->fetch($obj->rowid);
 $prev_progress = $line->get_prev_progress();
 if ($obj->type == Facture::TYPE_SITUATION) {
     // Avoid divide by 0
     if ($obj->situation_percent == 0) {
         $situation_ratio = 0;
     } else {
         $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
     }
 } else {
     $situation_ratio = 1;
 }
 // Invoice lines
 $tabfac[$obj->rowid]["date"] = $obj->df;
 $tabfac[$obj->rowid]["ref"] = $obj->facnumber;
Beispiel #3
0
 /**
  *	Delete line in database
  *
  *	@param		int		$rowid		Id of line to delete
  *	@return		int					<0 if KO, >0 if OK
  */
 function deleteline($rowid)
 {
     global $langs, $conf;
     dol_syslog(get_class($this) . "::deleteline rowid=" . $rowid, LOG_DEBUG);
     if (!$this->brouillon) {
         $this->error = 'ErrorBadStatus';
         return -1;
     }
     $this->db->begin();
     // Libere remise liee a ligne de facture
     $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'societe_remise_except';
     $sql .= ' SET fk_facture_line = NULL';
     $sql .= ' WHERE fk_facture_line = ' . $rowid;
     dol_syslog(get_class($this) . "::deleteline", LOG_DEBUG);
     $result = $this->db->query($sql);
     if (!$result) {
         $this->error = $this->db->error();
         $this->db->rollback();
         return -1;
     }
     $line = new FactureLigne($this->db);
     $line->context = $this->context;
     // For triggers
     $line->fetch($rowid);
     if ($line->delete() > 0) {
         $result = $this->update_price(1);
         if ($result > 0) {
             $this->db->commit();
             return 1;
         } else {
             $this->db->rollback();
             $this->error = $this->db->lasterror();
             return -1;
         }
     } else {
         $this->db->rollback();
         $this->error = $line->error;
         return -1;
     }
 }
Beispiel #4
0
/**
 * Mise a jour des totaux lignes de facture
 *
 * @param	DoliDB		$db		Database handler
 * @param	Translate	$langs	Object langs
 * @param	Conf		$conf	Object conf
 * @return	void
 */
function migrate_price_facture($db, $langs, $conf)
{
    $err = 0;
    $db->begin();
    print '<tr><td colspan="4">';
    print '<br>';
    print '<b>' . $langs->trans('MigrationInvoice') . "</b><br>\n";
    // Liste des lignes facture non a jour
    $sql = "SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as tva_taux, fd.total_ttc, fd.info_bits,";
    $sql .= " f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
    $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd, " . MAIN_DB_PREFIX . "facture as f";
    $sql .= " WHERE fd.fk_facture = f.rowid";
    $sql .= " AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
    //print $sql;
    dolibarr_install_syslog("upgrade2::migrate_price_facture", 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;
                $total_ttc_f = $obj->total_ttc_f;
                $info_bits = $obj->info_bits;
                // On met a jour les 3 nouveaux champs
                $facligne = new FactureLigne($db);
                $facligne->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];
                $facligne->total_ht = $total_ht;
                $facligne->total_tva = $total_tva;
                $facligne->total_ttc = $total_ttc;
                dolibarr_install_syslog("upgrade2: Line {$rowid}: facid={$obj->facid} pu={$pu} qty={$qty} tva_taux={$txtva} remise_percent={$remise_percent} remise_global={$remise_percent_global} -> {$total_ht}, {$total_tva}, {$total_ttc}");
                print ". ";
                $facligne->update_total();
                /* On touche a facture mere uniquement si total_ttc = 0 */
                if (!$total_ttc_f) {
                    $facture = new Facture($db);
                    $facture->id = $obj->facid;
                    if ($facture->fetch($facture->id) >= 0) {
                        if ($facture->update_price() > 0) {
                            //print $facture->id;
                        } else {
                            print "Error id=" . $facture->id;
                            $err++;
                        }
                    } else {
                        print "Error #3";
                        $err++;
                    }
                }
                print " ";
                $i++;
            }
        } else {
            print $langs->trans("AlreadyDone");
        }
        $db->free($resql);
        $db->commit();
    } else {
        print "Error #1 " . $db->error();
        $err++;
        $db->rollback();
    }
    print '<br>';
    print '</td></tr>';
}