/**
  * Envoie la liste de produit fini à la vue index.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     try {
         $user = Auth::user();
         $role = $user->role;
         $entrepots = Entrepot::All();
         $produits = ProduitFini::All();
         //$listeProduitsEntrepot = entrepot->pivot->
     } catch (ModelNotFoundException $e) {
         App::abort(404);
     }
     return View::make('produitsFinis.index', compact('produits', 'role', 'entrepots'));
 }
Example #2
0
   print $doleditor->Create(1);*/
 print "</td></tr>";
 // Note Private
 print '<tr><td>' . $langs->trans("NotePrivate") . '</td>';
 print '<td colspan="3">';
 print nl2br($object->note_private);
 /*$doleditor = new DolEditor('note_pprivate', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
   print $doleditor->Create(1);*/
 print "</td></tr>";
 // Statut
 print '<tr><td>' . $langs->trans("Status") . '</td>';
 print '<td colspan="3">' . $object->getLibStatut(4) . "</td>\n";
 print '</tr>';
 if (!$conf->expedition_bon->enabled && !empty($conf->stock->enabled)) {
     // Entrepot
     $entrepot = new Entrepot($db);
     $entrepot->fetch($object->entrepot_id);
     print '<tr><td width="20%">' . $langs->trans("Warehouse") . '</td>';
     print '<td colspan="3"><a href="' . DOL_URL_ROOT . '/product/stock/card.php?id=' . $entrepot->id . '">' . $entrepot->libelle . '</a></td>';
     print '</tr>';
 }
 print "</table><br>\n";
 /*
  * Lignes produits
  */
 $num_prod = count($object->lines);
 $i = 0;
 $total = 0;
 print '<table class="noborder" width="100%">';
 if ($num_prod) {
     $i = 0;
Example #3
0
print '<td align="right">'.$langs->trans("AverageUnitPricePMPShort").'</td>';
print '<td align="right">'.$langs->trans("EstimatedStockValueShort").'</td>';
print '<td align="right">'.$langs->trans("SellPriceMin").'</td>';
print '<td align="right">'.$langs->trans("EstimatedStockValueSellShort").'</td>';
print '</tr>';

$sql = "SELECT e.rowid, e.label, ps.reel, ps.pmp";
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
$sql.= " ".MAIN_DB_PREFIX."product_stock as ps";
$sql.= " WHERE ps.reel != 0";
$sql.= " AND ps.fk_entrepot = e.rowid";
$sql.= " AND e.entity = ".$conf->entity;
$sql.= " AND ps.fk_product = ".$product->id;
$sql.= " ORDER BY e.label";

$entrepotstatic=new Entrepot($db);
$total=0;
$totalvalue=$totalvaluesell=0;

$resql=$db->query($sql);
if ($resql)
{
	$num = $db->num_rows($resql);
	$total=$totalwithpmp;
	$i=0; $var=false;
	while ($i < $num)
	{
		$obj = $db->fetch_object($resql);
		$entrepotstatic->id=$obj->rowid;
		$entrepotstatic->libelle=$obj->label;
		print '<tr '.$bc[$var].'>';
    }
    print '</td></tr>';
    print '<tr><td>' . $langs->trans("Status") . '</td><td colspan="3">';
    print '<select name="statut" class="flat">';
    print '<option value="0">' . $langs->trans("WarehouseClosed") . '</option>';
    print '<option value="1" selected="selected">' . $langs->trans("WarehouseOpened") . '</option>';
    print '</select>';
    print '</td></tr>';
    print '</table>';
    print '<center><br><input type="submit" class="button" value="' . $langs->trans("Create") . '"></center>';
    print '</form>';
} else {
    $id = GETPOST("id", 'int');
    if ($id) {
        dol_htmloutput_mesg($mesg);
        $object = new Entrepot($db);
        $result = $object->fetch($id);
        if ($result < 0) {
            dol_print_error($db);
        }
        /*
         * Affichage fiche
         */
        if ($action != 'edit' && $action != 're-edit') {
            $head = stock_prepare_head($object);
            dol_fiche_head($head, 'card', $langs->trans("Warehouse"), 0, 'stock');
            // Confirm delete third party
            if ($action == 'delete') {
                print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $object->id, $langs->trans("DeleteAWarehouse"), $langs->trans("ConfirmDeleteWarehouse", $object->libelle), "confirm_delete", '', 0, 2);
            }
            print '<table class="border" width="100%">';
        $result = $product->fetch($product_id);
        $result = $product->correct_stock($user, $id, $_POST["nbpiece"], $_POST["mouvement"], $_POST["label"], 0);
        // We do not change value of stock for a correction
        if ($result > 0) {
            header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
            exit;
        }
    } else {
        $action = '';
    }
}
/*
 * View
 */
$productstatic = new Product($db);
$warehousestatic = new Entrepot($db);
$movement = new MouvementStock($db);
$userstatic = new User($db);
$form = new Form($db);
$formother = new FormOther($db);
$formproduct = new FormProduct($db);
$sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.fk_product_type as type,";
$sql .= " e.label as stock, e.rowid as entrepot_id,";
$sql .= " m.rowid as mid, m.value, m.datem, m.fk_user_author, m.label, m.fk_origin, m.origintype,";
$sql .= " u.login";
// Checkpoint: obtener el checkbox
$sql .= ", m.checked";
$sql .= " FROM (" . MAIN_DB_PREFIX . "entrepot as e,";
$sql .= " " . MAIN_DB_PREFIX . "product as p,";
$sql .= " " . MAIN_DB_PREFIX . "stock_mouvement as m)";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u ON m.fk_user_author = u.rowid";
    $bankcash->fetch($_SESSION["CASHDESK_ID_BANKACCOUNT_CASH"]);
    $bankcash->label = $bankcash->ref;
    $bankcashLink = $bankcash->getNomUrl(1);
}
if (!empty($_SESSION["CASHDESK_ID_BANKACCOUNT_CB"])) {
    $bankcb = new Account($db);
    $bankcb->fetch($_SESSION["CASHDESK_ID_BANKACCOUNT_CB"]);
    $bankcbLink = $bankcb->getNomUrl(1);
}
if (!empty($_SESSION["CASHDESK_ID_BANKACCOUNT_CHEQUE"])) {
    $bankcheque = new Account($db);
    $bankcheque->fetch($_SESSION["CASHDESK_ID_BANKACCOUNT_CHEQUE"]);
    $bankchequeLink = $bankcheque->getNomUrl(1);
}
if (!empty($_SESSION["CASHDESK_ID_WAREHOUSE"]) && !empty($conf->stock->enabled)) {
    $warehouse = new Entrepot($db);
    $warehouse->fetch($_SESSION["CASHDESK_ID_WAREHOUSE"]);
    $warehouseLink = $warehouse->getNomUrl(1);
}
$langs->load("cashdesk");
$langs->load("main");
print '<div class="menu_bloc">';
print '<ul class="menu">';
// Link to new sell
print '<li class="menu_choix1"><a href="affIndex.php?menu=facturation&id=NOUV"><span>' . $langs->trans("NewSell") . '</span></a></li>';
// Open new tab on backoffice (this is not a disconnect from POS)
print '<li class="menu_choix2"><a href=".." target="backoffice"><span>' . $langs->trans("BackOffice") . '</span></a></li>';
// Disconnect
print '<li class="menu_choix0">' . $langs->trans("User") . ': ' . $_SESSION['firstname'] . ' ' . $_SESSION['lastname'];
print ' <a href="deconnexion.php">' . img_picto($langs->trans('Logout'), 'logout.png') . '</a><br>';
print $langs->trans("CashDeskThirdParty") . ': ' . $companyLink . '<br>';
Example #7
0
require("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/entrepot.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/stock.lib.php");

$langs->load("stocks");

/*
 * View
 */

$help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
llxHeader("",$langs->trans("Stocks"),$help_url);

$entrepot = new Entrepot($db);
$entrepot->fetch($_GET["id"]);
$entrepot->info($_GET["id"]);

$head = stock_prepare_head($entrepot);

dol_fiche_head($head, 'info', $langs->trans("Warehouse"), 0, 'stock');


print '<table width="100%"><tr><td>';
dol_print_object_info($entrepot);
print '</td></tr></table>';

print '</div>';

llxFooter();
Example #8
0
	print '</select>';
	print '</td></tr>';

	print '</table>';

	print '<center><br><input type="submit" class="button" value="'.$langs->trans("Create").'"></center>';

	print '</form>';
}
else
{
	if ($_GET["id"])
	{
		dol_htmloutput_mesg($mesg);

		$object = new Entrepot($db);
		$result = $object->fetch($_GET["id"]);
		if ($result < 0)
		{
			dol_print_error($db);
		}

		/*
		 * Affichage fiche
		 */
		if ($action <> 'edit' && $action <> 're-edit')
		{
			$head = stock_prepare_head($object);

			dol_fiche_head($head, 'card', $langs->trans("Warehouse"), 0, 'stock');
Example #9
0
 /**
  * testEntrepotDelete
  *
  * @param		int		$id		Id of entrepot
  * @return		void
  *
  * @depends	testEntrepotOther
  * The depends says test is run only if previous is ok
  */
 public function testEntrepotDelete($id)
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $localobject = new Entrepot($this->savdb);
     $result = $localobject->fetch($id);
     $result = $localobject->delete($id);
     print __METHOD__ . " id=" . $id . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     return $result;
 }
Example #10
0
     print '</td>';
 }
 print '<td class="liste_titre">&nbsp;</td>';
 print '<td class="liste_titre" align="center"><input class="flat" type="text" name="search_batch" size="6" value="' . $search_batch . '"></td>';
 print '<td class="liste_titre" align="right">&nbsp;</td>';
 print '<td class="liste_titre">&nbsp;</td>';
 print '<td class="liste_titre">&nbsp;</td>';
 print '<td class="liste_titre">&nbsp;</td>';
 print '<td class="liste_titre">&nbsp;</td>';
 print '<td class="liste_titre" align="right">';
 print '<input type="image" class="liste_titre" name="button_search" src="' . img_picto($langs->trans("Search"), 'search.png', '', '', 1) . '" alt="' . $langs->trans("Search") . '">';
 print '<input type="image" class="liste_titre" name="button_removefilter" src="' . img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1) . '" alt="' . $langs->trans("RemoveFilter") . '">';
 print '</td>';
 print '</tr>';
 $product_static = new Product($db);
 $warehousetmp = new Entrepot($db);
 $var = True;
 while ($i < min($num, $limit)) {
     $objp = $db->fetch_object($resql);
     // Multilangs
     if (!empty($conf->global->MAIN_MULTILANGS)) {
         $sql = "SELECT label";
         $sql .= " FROM " . MAIN_DB_PREFIX . "product_lang";
         $sql .= " WHERE fk_product=" . $objp->rowid;
         $sql .= " AND lang='" . $langs->getDefaultLang() . "'";
         $sql .= " LIMIT 1";
         $result = $db->query($sql);
         if ($result) {
             $objtp = $db->fetch_object($result);
             if (!empty($objtp->label)) {
                 $objp->label = $objtp->label;
/**
 * Update a product or service
 *
 * @param	array		$authentication		Array of authentication information
 * @param	Product		$product			Product
 * @return	array							Array result
 */
function updateProductOrService($authentication, $product)
{
    global $db, $conf, $langs;
    $now = dol_now();
    dol_syslog("Function: updateProductOrService login="******"You must choose between price or price_net to provide price.";
    }
    if ($product['barcode'] && !$product['barcode_type']) {
        $errror++;
        $errorcode = 'KO';
        $errorlabel = "You must set a barcode type when setting a barcode.";
    }
    if (!$error) {
        include_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
        $newobject = new Product($db);
        $newobject->fetch($product['id']);
        if (isset($product['ref'])) {
            $newobject->ref = $product['ref'];
        }
        if (isset($product['ref_ext'])) {
            $newobject->ref_ext = $product['ref_ext'];
        }
        $newobject->type = $product['type'];
        $newobject->libelle = $product['label'];
        // @deprecated
        $newobject->label = $product['label'];
        $newobject->description = $product['description'];
        $newobject->note = $product['note'];
        $newobject->status = $product['status_tosell'];
        $newobject->status_buy = $product['status_tobuy'];
        $newobject->price = $product['price_net'];
        $newobject->price_ttc = $product['price'];
        $newobject->tva_tx = $product['vat_rate'];
        $newobject->price_base_type = $product['price_base_type'];
        $newobject->date_creation = $now;
        if ($product['barcode']) {
            $newobject->barcode = $product['barcode'];
            $newobject->barcode_type = $product['barcode_type'];
        }
        $newobject->stock_reel = $product['stock_real'];
        $newobject->pmp = $product['pmp'];
        $newobject->seuil_stock_alert = $product['stock_alert'];
        $newobject->country_id = $product['country_id'];
        if ($product['country_code']) {
            $newobject->country_id = getCountry($product['country_code'], 3);
        }
        $newobject->customcode = $product['customcode'];
        $newobject->canvas = $product['canvas'];
        /*foreach($product['lines'] as $line)
          {
              $newline=new FactureLigne($db);
              $newline->type=$line['type'];
              $newline->desc=$line['desc'];
              $newline->fk_product=$line['fk_product'];
              $newline->total_ht=$line['total_net'];
              $newline->total_vat=$line['total_vat'];
              $newline->total_ttc=$line['total'];
              $newline->vat=$line['vat_rate'];
              $newline->qty=$line['qty'];
              $newline->fk_product=$line['product_id'];
          }*/
        //var_dump($product['ref_ext']);
        //var_dump($product['lines'][0]['type']);
        $extrafields = new ExtraFields($db);
        $extralabels = $extrafields->fetch_name_optionals_label('product', true);
        foreach ($extrafields->attribute_label as $key => $label) {
            $key = 'options_' . $key;
            $newobject->array_options[$key] = $product[$key];
        }
        $db->begin();
        $result = $newobject->update($newobject->id, $fuser);
        if ($result <= 0) {
            $error++;
        } else {
            // Update stock if stock count is provided and differs from database after creation or update
            if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) {
                require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
                $savstockreal = $newobject->stock_reel;
                $newobject->load_stock();
                // This overwrite ->stock_reel
                $getstockreal = $newobject->stock_reel;
                if ($savstockreal != $getstockreal) {
                    $warehouse = new Entrepot($this->db);
                    $warehouse->fetch(0, $product['warehouse_ref']);
                    if ($warehouse->id > 0) {
                        if ($savstockreal - $getstockreal > 0) {
                            $result = $newobject->correct_stock($fuser, $warehouse->id, $savstockreal - $getstockreal, 0, 'Correction from external call (Web Service)', 0, 'WS' . dol_print_date($now, 'dayhourlog'));
                        }
                        if ($savstockreal - $getstockreal > 0) {
                            $result = $newobject->correct_stock($fuser, $warehouse->id, $savstockreal - $getstockreal, 1, 'Correction from external call (Web Service)', 0, 'WS' . dol_print_date($now, 'dayhourlog'));
                        }
                        if ($result <= 0) {
                            $error++;
                            $newobject->error = 'You set a different value for stock, but correction of stock count (before=' . $getstockreal . ', after=' . $savstockreal . ') fails with error ' . $newobject->error;
                        }
                    } else {
                        $error++;
                        $newobject->error = 'You set a different value for stock but we failed to find warehouse ' . $product['warehouse_ref'] . ' to make correction.';
                    }
                }
            }
        }
        if (!$error) {
            if ($newobject->price_base_type == 'HT') {
                $result = $newobject->updatePrice($newobject->price, $newobject->price_base_type, $fuser);
                if ($result <= 0) {
                    $error++;
                }
            } elseif ($newobject->price_base_type == 'TTC') {
                $result = $newobject->updatePrice($newobject->price_ttc, $newobject->price_base_type);
                if ($result <= 0) {
                    $error++;
                }
            }
        }
        if (!$error) {
            $db->commit();
            $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $newobject->id, 'ref' => $newobject->ref);
        } else {
            $db->rollback();
            $error++;
            $errorcode = 'KO';
            $errorlabel = $newobject->error;
        }
    }
    if ($error) {
        $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
    }
    return $objectresp;
}
                </div> 
                
                <div onclick="_TPV.searchByStock(-6,_TPV.warehouseId);" class="botonStats" align="center" title=" " style="width: 48%">
                    <span ><?php 
echo $langs->trans('WorstSell');
?>
</span>
                    <span id="stockWorst" style="font-size:22px">0</span>
                </div> 
                
                <?php 
$list = array();
$list = POS::getWarehouse();
$num = count($list);
$i = 0;
$warehouse = new Entrepot($db);
while ($i < $num) {
    $warehouse->fetch($list[$i]['id']);
    $ret = $warehouse->nb_products();
    ?>
                <div onclick="_TPV.searchByStock(1,<?php 
    echo $list[$i]['id'];
    ?>
);" class="botonStats" align="center" title=" " style="width: 48%">
                   <span><?php 
    echo $warehouse->libelle;
    ?>
</span>
                    <span   style="font-size:22px"><?php 
    echo $ret['nb'];
    ?>
 /**
  *    Display form to select warehouse
  *
  *    @param    string  $page        Page
  *    @param    int     $selected    Id of warehouse
  *    @param    string  $htmlname    Name of select html field
  *    @param    int     $addempty    1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries.
  *    @return   void
  */
 function formSelectWarehouses($page, $selected = '', $htmlname = 'warehouse_id', $addempty = 0)
 {
     global $langs;
     if ($htmlname != "none") {
         print '<form method="POST" action="' . $page . '">';
         print '<input type="hidden" name="action" value="setwarehouse">';
         print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
         print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
         print '<tr><td>';
         print $this->selectWarehouses($selected, $htmlname, '', $addempty);
         print '</td>';
         print '<td align="left"><input type="submit" class="button" value="' . $langs->trans("Modify") . '"></td>';
         print '</tr></table></form>';
     } else {
         if ($selected) {
             require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
             $warehousestatic = new Entrepot($this->db);
             $warehousestatic->fetch($selected);
             print $warehousestatic->getNomUrl();
         } else {
             print "&nbsp;";
         }
     }
 }
function _list_already_dispatched(&$commande)
{
    global $db, $langs;
    // List of lines already dispatched
    $sql = "SELECT p.ref, p.label,";
    $sql .= " e.rowid as warehouse_id, e.label as entrepot,";
    $sql .= " cfd.rowid as dispatchlineid, cfd.fk_product, cfd.qty";
    if ((double) DOL_VERSION > 3.7) {
        $sql .= ", cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status";
    }
    $sql .= " FROM " . MAIN_DB_PREFIX . "product as p,";
    $sql .= " " . MAIN_DB_PREFIX . "commande_fournisseur_dispatch as cfd";
    $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entrepot as e ON cfd.fk_entrepot = e.rowid";
    $sql .= " WHERE cfd.fk_commande = " . $commande->id;
    $sql .= " AND cfd.fk_product = p.rowid";
    $sql .= " ORDER BY cfd.rowid ASC";
    $resql = $db->query($sql);
    if ($resql) {
        $num = $db->num_rows($resql);
        $i = 0;
        if ($num > 0) {
            print "<br/>\n";
            print load_fiche_titre($langs->trans("ReceivingForSameOrder"));
            print '<table class="noborder" width="100%">';
            print '<tr class="liste_titre">';
            print '<td>' . $langs->trans("Description") . '</td>';
            if (!empty($conf->productbatch->enabled) && (double) DOL_VERSION > 3.7) {
                print '<td>' . $langs->trans("batch_number") . '</td>';
                print '<td>' . $langs->trans("l_eatby") . '</td>';
                print '<td>' . $langs->trans("l_sellby") . '</td>';
            }
            print '<td align="right">' . $langs->trans("QtyDispatched") . '</td>';
            print '<td></td>';
            print '<td>' . $langs->trans("Warehouse") . '</td>';
            print '<td>' . $langs->trans("Comment") . '</td>';
            if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS) && (double) DOL_VERSION > 3.7) {
                print '<td align="center" colspan="2">' . $langs->trans("Status") . '</td>';
            }
            print "</tr>\n";
            $var = false;
            while ($i < $num) {
                $objp = $db->fetch_object($resql);
                print "<tr " . $bc[$var] . ">";
                print '<td>';
                print '<a href="' . DOL_URL_ROOT . '/product/fournisseurs.php?id=' . $objp->fk_product . '">' . img_object($langs->trans("ShowProduct"), 'product') . ' ' . $objp->ref . '</a>';
                print ' - ' . $objp->label;
                print "</td>\n";
                if (!empty($conf->productbatch->enabled) && (double) DOL_VERSION > 3.7) {
                    print '<td>' . $objp->batch . '</td>';
                    print '<td>' . dol_print_date($db->jdate($objp->eatby), 'day') . '</td>';
                    print '<td>' . dol_print_date($db->jdate($objp->sellby), 'day') . '</td>';
                }
                // Qty
                print '<td align="right">' . $objp->qty . '</td>';
                print '<td>&nbsp;</td>';
                // Warehouse
                print '<td>';
                $warehouse_static = new Entrepot($db);
                $warehouse_static->id = $objp->warehouse_id;
                $warehouse_static->libelle = $objp->entrepot;
                print $warehouse_static->getNomUrl(1);
                print '</td>';
                // Comment
                print '<td>' . dol_trunc($objp->comment) . '</td>';
                // Status
                if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS) && (double) DOL_VERSION > 3.7) {
                    print '<td align="right">';
                    $supplierorderdispatch->status = empty($objp->status) ? 0 : $objp->status;
                    //print $supplierorderdispatch->status;
                    print $supplierorderdispatch->getLibStatut(5);
                    print '</td>';
                    // Add button to check/uncheck disaptching
                    print '<td align="center">';
                    if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner) || !empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)) {
                        if (empty($objp->status)) {
                            print '<a class="button buttonRefused" href="#">' . $langs->trans("Approve") . '</a>';
                            print '<a class="button buttonRefused" href="#">' . $langs->trans("Deny") . '</a>';
                        } else {
                            print '<a class="button buttonRefused" href="#">' . $langs->trans("Disapprove") . '</a>';
                            print '<a class="button buttonRefused" href="#">' . $langs->trans("Deny") . '</a>';
                        }
                    } else {
                        $disabled = '';
                        if ($commande->statut == 5) {
                            $disabled = 1;
                        }
                        if (empty($objp->status)) {
                            print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=checkdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Approve") . '</a>';
                            print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=denydispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Deny") . '</a>';
                        }
                        if ($objp->status == 1) {
                            print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=uncheckdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Reinit") . '</a>';
                            print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=denydispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Deny") . '</a>';
                        }
                        if ($objp->status == 2) {
                            print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=uncheckdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Reinit") . '</a>';
                            print '<a class="button' . ($disabled ? ' buttonRefused' : '') . '" href="' . $_SERVER["PHP_SELF"] . "?id=" . $id . "&action=checkdispatchline&lineid=" . $objp->dispatchlineid . '">' . $langs->trans("Approve") . '</a>';
                        }
                    }
                    print '</td>';
                }
                print "</tr>\n";
                $i++;
                $var = !$var;
            }
            $db->free($resql);
            print "</table>\n";
        }
    } else {
        dol_print_error($db);
    }
}
Example #15
0
    print '<tr class="liste_titre"><td width="10%"></td>';
    print '<td align="right" width="10%">' . $langs->trans("batch_number") . '</td>';
    print '<td align="center" width="10%">' . $langs->trans("l_eatby") . '</td>';
    print '<td align="center" width="10%">' . $langs->trans("l_sellby") . '</td>';
    print '<td align="right" colspan="5"></td>';
    print '</tr>';
}
$sql = "SELECT e.rowid, e.label, e.lieu, ps.reel, ps.pmp, ps.rowid as product_stock_id";
$sql .= " FROM " . MAIN_DB_PREFIX . "entrepot as e,";
$sql .= " " . MAIN_DB_PREFIX . "product_stock as ps";
$sql .= " WHERE ps.reel != 0";
$sql .= " AND ps.fk_entrepot = e.rowid";
$sql .= " AND e.entity IN (" . getEntity('stock', 1) . ")";
$sql .= " AND ps.fk_product = " . $product->id;
$sql .= " ORDER BY e.label";
$entrepotstatic = new Entrepot($db);
$total = 0;
$totalvalue = $totalvaluesell = 0;
$resql = $db->query($sql);
if ($resql) {
    $num = $db->num_rows($resql);
    $total = $totalwithpmp;
    $i = 0;
    $var = false;
    while ($i < $num) {
        $obj = $db->fetch_object($resql);
        $entrepotstatic->id = $obj->rowid;
        $entrepotstatic->libelle = $obj->label;
        $entrepotstatic->lieu = $obj->lieu;
        print '<tr ' . $bc[$var] . '>';
        print '<td colspan="4">' . $entrepotstatic->getNomUrl(1) . '</td>';
        // Redirect to avoid pb when using back
        exit;
    } else {
        $db->rollback();
        setEventMessage($langs->trans("Error"), 'errors');
    }
}
/*
 * View
 */
$now = dol_now();
$form = new Form($db);
$formproduct = new FormProduct($db);
$productstatic = new Product($db);
$warehousestatics = new Entrepot($db);
$warehousestatict = new Entrepot($db);
$title = $langs->trans('MassMovement');
llxHeader('', $title, $helpurl, '');
print_fiche_titre($langs->trans("MassStockMovement")) . '<br><br>';
$titletoadd = $langs->trans("Select");
$titletoaddnoent = $langs->transnoentitiesnoconv("Select");
$buttonrecord = $langs->trans("RecordMovement");
$buttonrecordnoent = $langs->trans("RecordMovement");
print $langs->trans("SelectProductInAndOutWareHouse", $titletoaddnoent, $buttonrecordnoent) . '<br>';
print '<br>' . "\n";
$var = true;
// Form to add a line
print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST" name="formulaire">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="addline">';
print '<table class="liste" width="100%">';
Example #17
0
         print '</td>';
         // Volume
         print '<td align="center">';
         if ($lines[$i]->fk_product_type == 0) {
             print $lines[$i]->volume * $lines[$i]->qty_shipped . ' ' . measuring_units_string($lines[$i]->volume_units, "volume");
         } else {
             print '&nbsp;';
         }
         print '</td>';
         // Size
         //print '<td align="center">'.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume").'</td>';
         // Entrepot source
         if ($conf->stock->enabled) {
             print '<td align="left">';
             if ($lines[$i]->entrepot_id > 0) {
                 $entrepot = new Entrepot($db);
                 $entrepot->fetch($lines[$i]->entrepot_id);
                 print $entrepot->getNomUrl(1);
             }
             print '</td>';
         }
         print "</tr>";
         $var = !$var;
     }
 }
 print "</table>\n";
 print "\n</div>\n";
 /*
  *    Boutons actions
  */
 if ($user->societe_id == 0) {
Example #18
0
/*
 * View
 */

$help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
llxHeader("",$langs->trans("WarehouseCard"),$help_url);

$form=new Form($db);


if ($_GET["id"])
{
	if ($mesg) print $mesg;

	$entrepot = new Entrepot($db);
	$result = $entrepot->fetch($_GET["id"]);
	if ($result < 0)
	{
		dol_print_error($db);
	}

	/*
	 * Affichage fiche
	 */
	if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit')
	{

		$head = stock_prepare_head($entrepot);

		dol_fiche_head($head, 'user', $langs->trans("Warehouse"), 0, 'stock');
Example #19
0
 print '</td>';
 // Size
 //print '<td align="center">'.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume").'</td>';
 // Entrepot source
 if (!empty($conf->stock->enabled)) {
     print '<td align="left">';
     if ($lines[$i]->entrepot_id > 0) {
         $entrepot = new Entrepot($db);
         $entrepot->fetch($lines[$i]->entrepot_id);
         print $entrepot->getNomUrl(1);
     } else {
         if (count($lines[$i]->details_entrepot) > 1) {
             $detail = '';
             foreach ($lines[$i]->details_entrepot as $detail_entrepot) {
                 if ($detail_entrepot->entrepot_id > 0) {
                     $entrepot = new Entrepot($db);
                     $entrepot->fetch($detail_entrepot->entrepot_id);
                     $detail .= $langs->trans("DetailWarehouseFormat", $entrepot->libelle, $detail_entrepot->qty_shipped) . '<br/>';
                 }
             }
             print $form->textwithtooltip($langs->trans("DetailWarehouseNumber"), $detail);
         }
     }
     print '</td>';
 }
 // Batch number managment
 if (!empty($conf->productbatch->enabled)) {
     if (isset($lines[$i]->detail_batch)) {
         print '<td>';
         if ($lines[$i]->product_tobatch) {
             $detail = '';
Example #20
0
 /**
  * testMouvementCreate
  *
  * @return	int
  */
 public function testMouvementCreate()
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     // We create a product for tests
     $product1 = new Product($db);
     $product1->initAsSpecimen();
     $product1->ref .= ' 1';
     $product1->label .= ' 1';
     $product1id = $product1->create($user);
     $product2 = new Product($db);
     $product2->initAsSpecimen();
     $product2->ref .= ' 2';
     $product2->label .= ' 2';
     $product2id = $product2->create($user);
     // We create a product for tests
     $warehouse1 = new Entrepot($db);
     $warehouse1->initAsSpecimen();
     $warehouse1->libelle .= ' 1';
     $warehouse1->description .= ' 1';
     $warehouse1id = $warehouse1->create($user);
     $warehouse2 = new Entrepot($db);
     $warehouse2->initAsSpecimen();
     $warehouse2->libelle .= ' 2';
     $warehouse2->description .= ' 2';
     $warehouse2id = $warehouse2->create($user);
     $localobject = new MouvementStock($this->savdb);
     // Do a list of movement into warehouse 1
     // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9
     $result = $localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.9, 'Movement for unit test 1', 'Inventory Code Test');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.699999999999999, 'Movement for unit test 2', 'Inventory Code Test');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse1id, -5, 2, 999, 'Movement for unit test 3', 'Inventory Code Test');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse1id, 1, 0, 0, 'Input from transfer', 'Transfert X');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse1id, -2, 1, 0, 'Output from transfer', 'Transfert Y');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Do same but into warehouse 2
     // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9
     $result = $localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.9, 'Movement for unit test 1 wh 2', 'Inventory Code Test 2');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.699999999999999, 'Movement for unit test 2 wh 2', 'Inventory Code Test 2');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse2id, -5, 2, 999, 'Movement for unit test 3 wh 2', 'Inventory Code Test 2');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse2id, 1, 0, 0, 'Input from transfer wh 2', 'Transfert X 2');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse2id, -2, 1, 0, 'Output from transfer wh 2', 'Transfert Y 2');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     return $localobject;
 }
Example #21
0
 // Confirm back to draft status
 if ($action == 'modif') {
     $text = $langs->trans('ConfirmUnvalidateBill', $object->ref);
     $formquestion = array();
     $qualified_for_stock_change = 0;
     if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
         $qualified_for_stock_change = $object->hasProductsOrServices(2);
     } else {
         $qualified_for_stock_change = $object->hasProductsOrServices(1);
     }
     if ($object->type != Facture::TYPE_DEPOSIT && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) {
         $langs->load("stocks");
         require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
         require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
         $formproduct = new FormProduct($db);
         $warehouse = new Entrepot($db);
         $warehouse_array = $warehouse->list_array();
         if (count($warehouse_array) == 1) {
             $label = $object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans("WarehouseForStockIncrease", current($warehouse_array));
             $value = '<input type="hidden" id="idwarehouse" name="idwarehouse" value="' . key($warehouse_array) . '">';
         } else {
             $label = $object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease");
             $value = $formproduct->selectWarehouses(GETPOST('idwarehouse') ? GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1);
         }
         $formquestion = array(array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $value));
     }
     $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('UnvalidateBill'), $text, 'confirm_modif', $formquestion, "yes", 1);
 }
 // Confirmation du classement paye
 if ($action == 'paid' && $resteapayer <= 0) {
     $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $object->ref), 'confirm_paid', '', "yes", 1);
         print '<td colspan="3">';
         $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $cash->id, $cash->fk_modepaybank_extra, 'none');
         print "</td>";
         print '</tr>';
     } else {
         print '<tr>';
         print '<td>' . $langs->trans('PaymentBankExtra') . '</td>';
         print '<td colspan="3">';
         //print $bankline->getNomUrl(1,0,'showall');
         print '</td>';
         print '</tr>';
     }
 }
 //Stock
 if ($conf->stock->enabled) {
     $stock = new Entrepot($db);
     $stock->fetch($cash->fk_warehouse);
     print '<tr><td>' . $langs->trans("CashDeskIdWareHouse") . '</td>';
     print '<td colspan="3">';
     print '<a href="' . DOL_URL_ROOT . '/product/stock/fiche.php?id=' . $stock->id . '">' . img_object($langs->trans("ShowWarehouse"), 'stock') . ' ' . $stock->libelle . '</a>';
     print '</td></tr>';
 }
 //Soc
 $soc = new Societe($db, $cash->fk_soc);
 $soc->fetch($cash->fk_soc);
 print '<tr><td>' . $langs->trans("CashDeskThirdPartyForSell") . '</td>';
 print '<td>';
 print $soc->getNomUrl(1, 'compta');
 print '</td></tr>';
 if ($conf->global->POS_USER_TERMINAL) {
     // Liste les commerciaux
Example #23
0
print "<tr " . $bc[false] . "><td>" . $langs->trans("Other") . ':</td><td><input type="text" name="sall" class="flat" size="18"></td>';
print "</table></form><br>";
$sql = "SELECT e.label, e.rowid, e.statut";
$sql .= " FROM " . MAIN_DB_PREFIX . "entrepot as e";
$sql .= " WHERE e.statut in (0,1)";
$sql .= " AND e.entity IN (" . getEntity('stock', 1) . ")";
$sql .= $db->order('e.statut', 'DESC');
$sql .= $db->plimit(15, 0);
$result = $db->query($sql);
if ($result) {
    $num = $db->num_rows($result);
    $i = 0;
    print '<table class="noborder" width="100%">';
    print '<tr class="liste_titre"><td colspan="2">' . $langs->trans("Warehouses") . '</td></tr>';
    if ($num) {
        $entrepot = new Entrepot($db);
        $var = True;
        while ($i < $num) {
            $objp = $db->fetch_object($result);
            $var = !$var;
            print "<tr " . $bc[$var] . ">";
            print "<td><a href=\"card.php?id={$objp->rowid}\">" . img_object($langs->trans("ShowStock"), "stock") . " " . $objp->label . "</a></td>\n";
            print '<td align="right">' . $entrepot->LibStatut($objp->statut, 5) . '</td>';
            print "</tr>\n";
            $i++;
        }
        $db->free($result);
    }
    print "</table>";
} else {
    dol_print_error($db);
Example #24
0

		$disabled=1;
		if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) $disabled=0;

		/*
		 * Lignes de commandes
		 */
		if ($commande->statut <= 2 || $commande->statut >= 6)
		{
			print $langs->trans("OrderStatusNotReadyToDispatch");
		}

		if ($commande->statut == 3 || $commande->statut == 4 || $commande->statut == 5)
		{
			$entrepot = new Entrepot($db);
			$listwarehouses=$entrepot->list_array(1);

			print '<form method="POST" action="dispatch.php?id='.$commande->id.'">';
			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
			print '<input type="hidden" name="action" value="dispatch">';
			print '<table class="noborder" width="100%">';

			$sql = "SELECT cfd.fk_product, sum(cfd.qty) as qty";
			$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd";
			$sql.= " WHERE cfd.fk_commande = ".$commande->id;
			$sql.= " GROUP BY cfd.fk_product";

			$resql = $db->query($sql);
			if ($resql)
			{
Example #25
0
			// Date delivery real / Received
			// TODO Can edit this date, even if delivery validated.
			print '<tr><td>'.$langs->trans("DateReceived").'</td>';
			print '<td colspan="3">'.dol_print_date($delivery->date_delivery,'daytext')."</td>\n";
			print '</tr>';

			// Statut
			print '<tr><td>'.$langs->trans("Status").'</td>';
			print '<td colspan="3">'.$delivery->getLibStatut(4)."</td>\n";
			print '</tr>';

			if (!$conf->expedition_bon->enabled && $conf->stock->enabled)
			{
				// Entrepot
				$entrepot = new Entrepot($db);
				$entrepot->fetch($delivery->entrepot_id);
				print '<tr><td width="20%">'.$langs->trans("Warehouse").'</td>';
				print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/product/stock/fiche.php?id='.$entrepot->id.'">'.$entrepot->libelle.'</a></td>';
				print '</tr>';
			}

			print "</table><br>\n";

			/*
			 * Lignes produits
			 */

			$num_prod = sizeof($delivery->lines);
			$i = 0; $total = 0;
Example #26
0
 /**
  *  Create a user into database
  *
  *  @param	User	$user        	Objet user doing creation
  *  @param  int		$notrigger		1=do not execute triggers, 0 otherwise
  *  @return int			         	<0 if KO, id of created user if OK
  */
 function create($user, $notrigger = 0)
 {
     global $conf, $langs;
     global $mysoc;
     // Clean parameters
     $this->login = trim($this->login);
     if (!isset($this->entity)) {
         $this->entity = $conf->entity;
     }
     // If not defined, we use default value
     dol_syslog(get_class($this) . "::create login="******", user="******"errors");
         $this->error = $langs->trans("ErrorBadEMail", $this->email);
         return -1;
     }
     if (empty($this->login)) {
         $langs->load("errors");
         $this->error = $langs->trans("ErrorFieldRequired", $this->login);
         return -1;
     }
     $this->datec = dol_now();
     $error = 0;
     $this->db->begin();
     $sql = "SELECT login FROM " . MAIN_DB_PREFIX . "user";
     $sql .= " WHERE login ='******'";
     $sql .= " AND entity IN (0," . $this->db->escape($conf->entity) . ")";
     dol_syslog(get_class($this) . "::create", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         $num = $this->db->num_rows($resql);
         $this->db->free($resql);
         if ($num) {
             $this->error = 'ErrorLoginAlreadyExists';
             dol_syslog(get_class($this) . "::create " . $this->error, LOG_WARNING);
             $this->db->rollback();
             return -6;
         } else {
             $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user (datec,login,ldap_sid,entity)";
             $sql .= " VALUES('" . $this->db->idate($this->datec) . "','" . $this->db->escape($this->login) . "','" . $this->db->escape($this->ldap_sid) . "'," . $this->db->escape($this->entity) . ")";
             $result = $this->db->query($sql);
             dol_syslog(get_class($this) . "::create", LOG_DEBUG);
             if ($result) {
                 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "user");
                 // Set default rights
                 if ($this->set_default_rights() < 0) {
                     $this->error = 'ErrorFailedToSetDefaultRightOfUser';
                     $this->db->rollback();
                     return -5;
                 }
                 // Update minor fields
                 $result = $this->update($user, 1, 1);
                 if ($result < 0) {
                     $this->db->rollback();
                     return -4;
                 }
                 if (!empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) {
                     require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
                     $langs->load("stocks");
                     $entrepot = new Entrepot($this->db);
                     $entrepot->libelle = $langs->trans("PersonalStock", $this->getFullName($langs));
                     $entrepot->description = $langs->trans("ThisWarehouseIsPersonalStock", $this->getFullName($langs));
                     $entrepot->statut = 1;
                     $entrepot->country_id = $mysoc->country_id;
                     $entrepot->create($user);
                 }
                 if (!$notrigger) {
                     // Call trigger
                     $result = $this->call_trigger('USER_CREATE', $user);
                     if ($result < 0) {
                         $error++;
                     }
                     // End call triggers
                 }
                 if (!$error) {
                     $this->db->commit();
                     return $this->id;
                 } else {
                     //$this->error=$interface->error;
                     dol_syslog(get_class($this) . "::create " . $this->error, LOG_ERR);
                     $this->db->rollback();
                     return -3;
                 }
             } else {
                 $this->error = $this->db->lasterror();
                 $this->db->rollback();
                 return -2;
             }
         }
     } else {
         $this->error = $this->db->lasterror();
         $this->db->rollback();
         return -1;
     }
 }
 /**		Return next value
  *      @param      objsoc      Object third party
  *      @param      ticket		Object ticket
  *      @param      mode        'next' for next value or 'last' for last value
  *      @return     string      Value if OK, 0 if KO
  */
 function getNextValue($objsoc, $facsim, $mode = 'next')
 {
     global $db, $conf;
     require_once DOL_DOCUMENT_ROOT . "/core/lib/functions2.lib.php";
     // Get Mask value
     $mask = '';
     if (is_object($facsim) && $facsim->type == 2) {
         $mask = $conf->global->FACSIM_MURO_MASK_CREDIT;
     } else {
         $mask = $conf->global->FACSIM_MURO_MASK;
     }
     if (!$mask) {
         $this->error = 'NotConfigured';
         return 0;
     }
     $where = '';
     //ww para warehouse
     if (preg_match('/\\{(w+)\\}/i', $mask, $regWare)) {
         dol_include_once("/pos/class/cash.class.php");
         require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
         $terminal = new Cash($db);
         $terminal->fetch($facsim->fk_cash);
         $warehouse = new Entrepot($db);
         $warehouse->fetch($terminal->fk_warehouse);
         $maskware = $regWare[1];
         $maskware_value = substr($warehouse->libelle, 0, dol_strlen($regWare[1]));
         //get n first characters of warehouse ref where n is length in mask
         $maskware_value = str_pad($maskware_value, dol_strlen($regWare[1]), "#", STR_PAD_RIGHT);
         $maskware_maskbefore = '{' . $maskware . '}';
         $maskware_maskafter = $maskware_value;
         $mask = str_replace($maskware_maskbefore, $maskware_maskafter, $mask);
     }
     //kk para terminal
     if (preg_match('/\\{(k+)\\}/i', $mask, $regTerm)) {
         dol_include_once("/pos/class/cash.class.php");
         $terminal = new Cash($db);
         $terminal->fetch($facsim->fk_cash);
         $maskterm = $regTerm[1];
         $maskterm_value = substr($terminal->ref, 0, dol_strlen($regTerm[1]));
         //get n first characters of warehouse ref where n is length in mask
         $maskterm_value = str_pad($maskterm_value, dol_strlen($regTerm[1]), "#", STR_PAD_RIGHT);
         $maskterm_maskbefore = '{' . $maskterm . '}';
         $maskterm_maskafter = $maskterm_value;
         $mask = str_replace($maskterm_maskbefore, $maskterm_maskafter, $mask);
     }
     $numFinal = get_next_value($db, $mask, 'facture', 'facnumber', $where, $objsoc, time(), $mode);
     if (!preg_match('/([0-9])+/', $numFinal)) {
         $this->error = $numFinal;
     }
     return $numFinal;
 }
Example #28
0
	/**
	 *  Create a user into database
	 *  @param      user        	Objet user qui demande la creation
	 *  @param      notrigger		1 ne declenche pas les triggers, 0 sinon
	 *  @return     int         	<0 si KO, id compte cree si OK
	 */
	function create($user,$notrigger=0)
	{
		global $conf,$langs;

		// Clean parameters
		$this->login = trim($this->login);
		if (! isset($this->entity)) $this->entity=$conf->entity;	// If not defined, we use default value

		dol_syslog("User::Create login="******", user="******"errors");
			$this->error = $langs->trans("ErrorBadEMail",$this->email);
			return -1;
		}

		$now=dol_now();

		$error=0;
		$this->db->begin();

		$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user";
		$sql.= " WHERE login ='******'";
		$sql.= " AND entity IN (0,".$conf->entity.")";

		dol_syslog("User::Create sql=".$sql, LOG_DEBUG);
		$resql=$this->db->query($sql);
		if ($resql)
		{
			$num = $this->db->num_rows($resql);
			$this->db->free($resql);

			if ($num)
			{
				$this->error = 'ErrorLoginAlreadyExists';
				dol_syslog("User::Create ".$this->error, LOG_WARNING);
				$this->db->rollback();
				return -6;
			}
			else
			{
				$sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec,login,ldap_sid,entity)";
				$sql.= " VALUES('".$this->db->idate($now)."','".$this->db->escape($this->login)."','".$this->ldap_sid."',".$this->entity.")";
				$result=$this->db->query($sql);

				dol_syslog("User::Create sql=".$sql, LOG_DEBUG);
				if ($result)
				{
					$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."user");

					// Set default rights
					if ($this->set_default_rights() < 0)
					{
						$this->error=$this->db->error();
						$this->db->rollback();
						return -5;
					}

					// Update minor fields
					$result = $this->update($user,1,1);
					if ($result < 0)
					{
						$this->db->rollback();
						return -4;
					}

					if (! empty($conf->global->STOCK_USERSTOCK_AUTOCREATE))
					{
						require_once(DOL_DOCUMENT_ROOT."/product/stock/class/entrepot.class.php");
						$langs->load("stocks");
						$entrepot = new Entrepot($this->db);
						$entrepot->libelle = $langs->trans("PersonalStock",$this->nom);
						$entrepot->description = $langs->trans("ThisWarehouseIsPersonalStock",$this->prenom,$this->nom);
						$entrepot->statut = 1;
						$entrepot->create($user);
					}

					if (! $notrigger)
					{
						// Appel des triggers
						include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
						$interface = new Interfaces($this->db);
						$result = $interface->run_triggers('USER_CREATE',$this,$user,$langs,$conf);
						if ($result < 0) { $error++; $this->errors=$interface->errors; }
						// Fin appel triggers
					}

					if (! $error)
					{
						$this->db->commit();
						return $this->id;
					}
					else
					{
						$this->error=$interface->error;
						dol_syslog("User::Create ".$this->error, LOG_ERR);
						$this->db->rollback();
						return -3;
					}
				}
				else
				{
					$this->error=$this->db->lasterror();
					dol_syslog("User::Create ".$this->error, LOG_ERR);
					$this->db->rollback();
					return -2;
				}
			}
		}
		else
		{
			$this->error=$this->db->lasterror();
			dol_syslog("User::Create ".$this->error, LOG_ERR);
			$this->db->rollback();
			return -1;
		}
	}