dolibarr  19.0.0-dev
interface.php
Go to the documentation of this file.
1 <?php
2 
7 if (!defined('NOREQUIRESOC')) {
8  define('NOREQUIRESOC', '1');
9 }
10 if (!defined('NOCSRFCHECK')) {
11  define('NOCSRFCHECK', '1');
12 }
13 if (!defined('NOTOKENRENEWAL')) {
14  define('NOTOKENRENEWAL', '1');
15 }
16 if (!defined('NOREQUIREMENU')) {
17  define('NOREQUIREMENU', '1');
18 }
19 if (!defined('NOREQUIREHTML')) {
20  define('NOREQUIREHTML', '1');
21 }
22 if (!defined('NOREQUIREAJAX')) {
23  define('NOREQUIREAJAX', '1');
24 }
25 
26 require '../../main.inc.php'; // Load $user and permissions
27 
28 $warehouse_id = GETPOST('warehouse_id', 'int');
29 $batch = GETPOST('batch', 'alphanohtml');
30 $fk_product = GETPOST('product_id', 'int');
31 $action = GETPOST('action', 'alphanohtml');
32 
33 $result = restrictedArea($user, 'mrp');
34 
35 $permissiontoproduce = $user->rights->mrp->write;
36 
37 
38 
39 /*
40  * View
41  */
42 
43 top_httphead("application/json");
44 
45 if ($action == 'updateselectbatchbywarehouse' && $permissiontoproduce) {
46  $TRes = array();
47 
48  $sql = "SELECT pb.batch, pb.rowid, ps.fk_entrepot, pb.qty, e.ref as label, ps.fk_product";
49  $sql .= " FROM " . MAIN_DB_PREFIX . "product_batch as pb";
50  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as ps on ps.rowid = pb.fk_product_stock";
51  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (" . getEntity('stock') . ")";
52  $sql .= " WHERE ps.fk_product = " .((int) $fk_product);
53  if ($warehouse_id > 0) $sql .= " AND fk_entrepot = '" . ((int) $warehouse_id) . "'";
54  $sql .= " ORDER BY e.ref, pb.batch";
55 
56  $resql = $db->query($sql);
57 
58  if ($resql) {
59  while ($obj = $db->fetch_object($resql)) {
60  if (empty($TRes[$obj->batch])) {
61  $TRes[$obj->batch] = $obj->qty;
62  } else {
63  $TRes[$obj->batch] += $obj->qty;
64  }
65  }
66  }
67 
68  echo json_encode($TRes);
69 } elseif ($action == 'updateselectwarehousebybatch' && $permissiontoproduce) {
70  $res = 0;
71 
72  $sql = "SELECT pb.batch, pb.rowid, ps.fk_entrepot, e.ref, pb.qty";
73  $sql .= " FROM " . MAIN_DB_PREFIX . "product_batch as pb";
74  $sql .= " JOIN " . MAIN_DB_PREFIX . "product_stock as ps on ps.rowid = pb.fk_product_stock";
75  $sql .= " JOIN " . MAIN_DB_PREFIX . "entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (" . getEntity('stock') . ")";
76  $sql .= " WHERE ps.fk_product = " .((int) $fk_product);
77  if ($batch) $sql.= " AND pb.batch = '" . $db->escape($batch) . "'";
78  $sql .= " ORDER BY e.ref, pb.batch";
79 
80  $resql = $db->query($sql);
81 
82  if ($resql) {
83  if ($db->num_rows($resql) == 1) {
84  $obj = $db->fetch_object($resql);
85  $res = $obj->fk_entrepot;
86  }
87  }
88 
89  echo json_encode($res);
90 }
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
if(!defined('NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1494
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.