dolibarr  9.0.0
Public Member Functions | Private Member Functions | List of all members
MouvementStock Class Reference

Class to manage stock movements. More...

+ Inheritance diagram for MouvementStock:
+ Collaboration diagram for MouvementStock:

Public Member Functions

 __construct ($db)
 Constructor. More...
 
 _create ($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='', $inventorycode='', $datem='', $eatby='', $sellby='', $batch='', $skip_batch=false, $id_product_batch=0)
 Add a movement of stock (in one direction only) More...
 
 fetch ($id)
 Load object in memory from the database. More...
 
 _createSubProduct ($user, $idProduct, $entrepot_id, $qty, $type, $price=0, $label='', $inventorycode='')
 Create movement in database for all subproducts. More...
 
 livraison ($user, $fk_product, $entrepot_id, $qty, $price=0, $label='', $datem='', $eatby='', $sellby='', $batch='', $id_product_batch=0)
 Decrease stock for product and subproducts. More...
 
 reception ($user, $fk_product, $entrepot_id, $qty, $price=0, $label='', $eatby='', $sellby='', $batch='')
 Increase stock for product and subproducts. More...
 
 calculateBalanceForProductBefore ($productidselected, $datebefore)
 Return nb of subproducts lines for a product. More...
 
 get_origin ($fk_origin, $origintype)
 Return Url link of origin object. More...
 
 setOrigin ($origin_element, $origin_id)
 Set attribute origin to object. More...
 
 initAsSpecimen ()
 Initialise an instance with random values. More...
 
 getNomUrl ($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
 Return a link (with optionaly the picto) Use this->id,this->lastname, this->firstname. More...
 
 getLibStatut ($mode=0)
 Return label statut. More...
 
 LibStatut ($mode=0)
 Renvoi le libelle d'un status donne. More...
 
 generateDocument ($modele, $outputlangs='', $hidedetails=0, $hidedesc=0, $hideref=0)
 Create object on disk. More...
 
- Public Member Functions inherited from CommonObject
 errorsToString ()
 Method to output saved errors. More...
 
 getFullName ($langs, $option=0, $nameorder=-1, $maxlen=0)
 Return full name (civility+' '+name+' '+lastname) More...
 
 getFullAddress ($withcountry=0, $sep="\, $withregion=0)
 Return full address of contact. More...
 
 getBannerAddress ($htmlkey, $object)
 Return full address for banner. More...
 
 getLastMainDocLink ($modulepart, $initsharekey=0, $relativelink=0)
 Return the link of last main doc file for direct public download. More...
 
 add_contact ($fk_socpeople, $type_contact, $source='external', $notrigger=0)
 Add a link between element $this->element and a contact. More...
 
 copy_linked_contact ($objFrom, $source='internal')
 Copy contact from one element to current. More...
 
 update_contact ($rowid, $statut, $type_contact_id=0, $fk_socpeople=0)
 Update a link to contact line. More...
 
 delete_contact ($rowid, $notrigger=0)
 Delete a link to contact line. More...
 
 delete_linked_contact ($source='', $code='')
 Delete all links between an object $this and all its contacts. More...
 
 liste_contact ($statut=-1, $source='external', $list=0, $code='')
 Get array of all contacts for an object. More...
 
 swapContactStatus ($rowid)
 Update status of a contact linked to object. More...
 
 liste_type_contact ($source='internal', $order='position', $option=0, $activeonly=0, $code='')
 Return array with list of possible values for type of contacts. More...
 
 getIdContact ($source, $code, $status=0)
 Return id of contacts for a source and a contact code. More...
 
 fetch_contact ($contactid=null)
 Load object contact with id=$this->contactid into $this->contact. More...
 
 fetch_thirdparty ($force_thirdparty_id=0)
 Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty. More...
 
 fetchOneLike ($ref)
 Looks for an object with ref matching the wildcard provided It does only work when $this->table_ref_field is set. More...
 
 fetch_barcode ()
 Load data for barcode into properties ->barcode_type* Properties ->barcode_type that is id of barcode. More...
 
 fetch_projet ()
 Load the project with id $this->fk_project into this->project. More...
 
 fetch_product ()
 Load the product with id $this->fk_product into this->product. More...
 
 fetch_user ($userid)
 Load the user with id $userid into this->user. More...
 
 fetch_origin ()
 Read linked origin object. More...
 
 fetchObjectFrom ($table, $field, $key, $element=null)
 Load object from specific field. More...
 
 getValueFrom ($table, $id, $field)
 Getter generic. More...
 
 setValueFrom ($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif')
 Setter generic. More...
 
 load_previous_next_ref ($filter, $fieldid, $nodbprefix=0)
 Load properties id_previous and id_next by comparing $fieldid with $this->ref. More...
 
 getListContactId ($source='external')
 Return list of id of contacts of object. More...
 
 setProject ($projectid)
 Link element with a project. More...
 
 setPaymentMethods ($id)
 Change the payments methods. More...
 
 setMulticurrencyCode ($code)
 Change the multicurrency code. More...
 
 setMulticurrencyRate ($rate, $mode=1)
 Change the multicurrency rate. More...
 
 setPaymentTerms ($id)
 Change the payments terms. More...
 
 setDeliveryAddress ($id)
 Define delivery address. More...
 
 setShippingMethod ($shipping_method_id, $notrigger=false, $userused=null)
 Change the shipping method. More...
 
 setWarehouse ($warehouse_id)
 Change the warehouse. More...
 
 setDocModel ($user, $modelpdf)
 Set last model used by doc generator. More...
 
 setBankAccount ($fk_account, $notrigger=false, $userused=null)
 Change the bank account. More...
 
 line_order ($renum=false, $rowidorder='ASC', $fk_parent_line=true)
 Save a new position (field rang) for details lines. More...
 
 getChildrenOfLine ($id)
 Get children of line. More...
 
 line_up ($rowid, $fk_parent_line=true)
 Update a line to have a lower rank. More...
 
 line_down ($rowid, $fk_parent_line=true)
 Update a line to have a higher rank. More...
 
 updateRangOfLine ($rowid, $rang)
 Update position of line (rang) More...
 
 line_ajaxorder ($rows)
 Update position of line with ajax (rang) More...
 
 updateLineUp ($rowid, $rang)
 Update position of line up (rang) More...
 
 updateLineDown ($rowid, $rang, $max)
 Update position of line down (rang) More...
 
 getRangOfLine ($rowid)
 Get position of line (rang) More...
 
 getIdOfLine ($rang)
 Get rowid of the line relative to its position. More...
 
 line_max ($fk_parent_line=0)
 Get max value used for position of line (rang) More...
 
 update_ref_ext ($ref_ext)
 Update external ref of element. More...
 
 update_note ($note, $suffix='')
 Update note of element. More...
 
 update_note_public ($note)
 Update public note (kept for backward compatibility) More...
 
 update_price ($exclspec=0, $roundingadjust='none', $nodatabaseupdate=0, $seller=null)
 Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines). More...
 
 add_object_linked ($origin=null, $origin_id=null)
 Add objects linked in llx_element_element. More...
 
 fetchObjectLinked ($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $clause='OR', $alsosametype=1, $orderby='sourcetype', $loadalsoobjects=1)
 Fetch array of objects linked to current object (object of enabled modules only). More...
 
 updateObjectLinked ($sourceid=null, $sourcetype='', $targetid=null, $targettype='')
 Update object linked of a current object. More...
 
 deleteObjectLinked ($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='')
 Delete all links between an object $this. More...
 
 setStatut ($status, $elementId=null, $elementType='', $trigkey='')
 Set status of an object. More...
 
 getCanvas ($id=0, $ref='')
 Load type of canvas of an object if it exists. More...
 
 getSpecialCode ($lineid)
 Get special code of a line. More...
 
 isObjectUsed ($id=0)
 Function to check if an object is used by others. More...
 
 hasProductsOrServices ($predefined=-1)
 Function to say how many lines object contains. More...
 
 getTotalDiscount ()
 Function that returns the total amount HT of discounts applied for all lines. More...
 
 getTotalWeightVolume ()
 Return into unit=0, the calculated total of weight and volume of all lines * qty Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. More...
 
 setExtraParameters ()
 Set extra parameters. More...
 
 display_incoterms ()
 Return incoterms informations TODO Use a cache for label get. More...
 
 getIncotermsForPDF ()
 Return incoterms informations for pdf display. More...
 
 setIncoterms ($id_incoterm, $location)
 Define incoterms values of current object. More...
 
 formAddObjectLine ($dateSelector, $seller, $buyer)
 Show add free and predefined products/services form. More...
 
 printObjectLines ($action, $seller, $buyer, $selected=0, $dateSelector=0)
 Return HTML table for object lines TODO Move this into an output class file (htmlline.class.php) If lines are into a template, title must also be into a template But for the moment we don't know if it's possible as we keep a method available on overloaded objects. More...
 
 printObjectLine ($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected=0, $extrafieldsline=0)
 Return HTML content of a detail line TODO Move this into an output class file (htmlline.class.php) More...
 
 printOriginLinesList ($restrictlist='')
 Return HTML table table of source object lines TODO Move this and previous function into output html class file (htmlline.class.php). More...
 
 printOriginLine ($line, $var, $restrictlist='')
 Return HTML with a line of table array of source object lines TODO Move this and previous function into output html class file (htmlline.class.php). More...
 
 add_element_resource ($resource_id, $resource_type, $busy=0, $mandatory=0)
 Add resources to the current object : add entry into llx_element_resources Need $this->element & $this->id. More...
 
 delete_resource ($rowid, $element, $notrigger=0)
 Delete a link to resource line. More...
 
 __clone ()
 Overwrite magic function to solve problem of cloning object that are kept as references. More...
 
 addThumbs ($file)
 Build thumb Move this into files.lib.php. More...
 
 getDefaultCreateValueFor ($fieldname, $alternatevalue=null)
 Return the default value to use for a field when showing the create form of object. More...
 
 call_trigger ($trigger_name, $user)
 Call trigger based on this instance. More...
 
 fetch_optionals ($rowid=null, $optionsArray=null)
 Function to get extra fields of an object into $this->array_options This method is in most cases called by method fetch of objects but you can call it separately. More...
 
 deleteExtraFields ()
 Delete all extra fields values for the current object. More...
 
 insertExtraFields ($trigger='', $userused=null)
 Add/Update all extra fields values for the current object. More...
 
 updateExtraField ($key, $trigger=null, $userused=null)
 Update an extra field value for the current object. More...
 
 showInputField ($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0)
 Return HTML string to put an input field into a page Code very similar with showInputField of extra fields. More...
 
 showOutputField ($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0)
 Return HTML string to show a field into a page Code very similar with showOutputField of extra fields. More...
 
 showOptionals ($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0)
 Function to show lines of extrafields with output datas. More...
 
 getRights ()
 Returns the rights used for this class. More...
 
 defineBuyPrice ($unitPrice=0.0, $discountPercent=0.0, $fk_product=0)
 Get buy price to use for margin calculation. More...
 
 show_photos ($modulepart, $sdir, $size=0, $nbmax=0, $nbbyrow=5, $showfilename=0, $showaction=0, $maxHeight=120, $maxWidth=160, $nolink=0, $notitle=0, $usesharelink=0)
 Show photos of an object (nbmax maximum), into several columns. More...
 
 isDate ($info)
 Function test if type is date. More...
 
 isInt ($info)
 Function test if type is integer. More...
 
 isFloat ($info)
 Function test if type is float. More...
 
 isText ($info)
 Function test if type is text. More...
 
 createCommon (User $user, $notrigger=false)
 Create object into database. More...
 
 fetchCommon ($id, $ref=null, $morewhere='')
 Load object in memory from the database. More...
 
 updateCommon (User $user, $notrigger=false)
 Update object into database. More...
 
 deleteCommon (User $user, $notrigger=false, $forcechilddeletion=0)
 Delete object in database. More...
 
 initAsSpecimenCommon ()
 Initialise object with example values Id must be 0 if object instance is a specimen. More...
 
 fetchComments ()
 Load comments linked with current task. More...
 
 getNbComments ()
 Return nb comments already posted. More...
 
 trimParameters ($parameters)
 Trim object parameters. More...
 

Private Member Functions

 createBatch ($dluo, $qty)
 Create or update batch record (update table llx_product_batch). More...
 

Additional Inherited Members

- Static Public Member Functions inherited from CommonObject
static isExistingObject ($element, $id, $ref='', $ref_ext='')
 Check an object id/ref exists If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch. More...
 
static commonReplaceThirdparty (DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
 Function used to replace a thirdparty id with another one. More...
 
- Public Attributes inherited from CommonObject
 $projet
 
 $note
 
- Protected Member Functions inherited from CommonObject
 commonGenerateDocument ($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
 Common function for all objects extending CommonObject for generating documents. More...
 
 isArray ($info)
 Function test if type is array. More...
 
 isNull ($info)
 Function test if type is null. More...
 
 isIndex ($info)
 Function test if is indexed. More...
 
 setSaveQuery ()
 Function to prepare the values to insert. More...
 
 setVarsFromFetchObj (&$obj)
 Function to load data from a SQL pointer into properties of current object $this. More...
 
 getFieldList ()
 Function to concat keys of fields. More...
 
 quote ($value, $fieldsentry)
 Add quote to field value if necessary. More...
 

Detailed Description

Class to manage stock movements.

Definition at line 31 of file mouvementstock.class.php.

Constructor & Destructor Documentation

◆ __construct()

MouvementStock::__construct (   $db)

Constructor.

Parameters
DoliDB$dbDatabase handler

Definition at line 86 of file mouvementstock.class.php.

Member Function Documentation

◆ _create()

MouvementStock::_create (   $user,
  $fk_product,
  $entrepot_id,
  $qty,
  $type,
  $price = 0,
  $label = '',
  $inventorycode = '',
  $datem = '',
  $eatby = '',
  $sellby = '',
  $batch = '',
  $skip_batch = false,
  $id_product_batch = 0 
)

Add a movement of stock (in one direction only)

Parameters
User$userUser object
int$fk_productId of product
int$entrepot_idId of warehouse
int$qtyQty of movement (can be <0 or >0 depending on parameter type)
int$typeDirection of movement: 0=input (stock increase by a stock transfer), 1=output (stock decrease after by a stock transfer), 2=output (stock decrease), 3=input (stock increase) Note that qty should be > 0 with 0 or 3, < 0 with 1 or 2.
int$priceUnit price HT of product, used to calculate average weighted price (PMP in french). If 0, average weighted price is not changed.
string$labelLabel of stock movement
string$inventorycodeInventory code
string$datemForce date of movement
date$eatbyeat-by date. Will be used if lot does not exists yet and will be created.
date$sellbysell-by date. Will be used if lot does not exists yet and will be created.
string$batchbatch number
boolean$skip_batchIf set to true, stock movement is done without impacting batch record
int$id_product_batchId product_batch (when skip_batch is false and we already know which record of product_batch to use)
Returns
int <0 if KO, 0 if fk_product is null, >0 if OK

Definition at line 114 of file mouvementstock.class.php.

Referenced by reception().

◆ _createSubProduct()

MouvementStock::_createSubProduct (   $user,
  $idProduct,
  $entrepot_id,
  $qty,
  $type,
  $price = 0,
  $label = '',
  $inventorycode = '' 
)

Create movement in database for all subproducts.

Parameters
User$userObject user
int$idProductId product
int$entrepot_idWarehouse id
int$qtyQuantity
int$typeType
int$pricePrice
string$labelLabel of movement
string$inventorycodeInventory code
Returns
int <0 if KO, 0 if OK

Definition at line 643 of file mouvementstock.class.php.

◆ calculateBalanceForProductBefore()

MouvementStock::calculateBalanceForProductBefore (   $productidselected,
  $datebefore 
)

Return nb of subproducts lines for a product.

Parameters
int$idId of product
Returns
int <0 if KO, nb of subproducts if OK
Deprecated:
A count($product->getChildsArbo($id,1)) is same. No reason to have this in this class.

Count number of product in stock before a specific date

Parameters
int$productidselectedId of product to count
timestamp$datebeforeDate limit
Returns
int Number

Definition at line 773 of file mouvementstock.class.php.

◆ createBatch()

MouvementStock::createBatch (   $dluo,
  $qty 
)
private

Create or update batch record (update table llx_product_batch).

No check is done here, done by parent.

Parameters
array | int$dluoCould be either
  • int if row id of product_batch table
  • or complete array('fk_product_stock'=>, 'batchnumber'=>)
int$qtyQuantity of product with batch number. May be a negative amount.
Returns
int <0 if KO, else return productbatch id

Definition at line 805 of file mouvementstock.class.php.

◆ fetch()

MouvementStock::fetch (   $id)

Load object in memory from the database.

Parameters
int$idId object
Returns
int <0 if KO, 0 if not found, >0 if OK

Definition at line 551 of file mouvementstock.class.php.

References dol_syslog().

◆ generateDocument()

MouvementStock::generateDocument (   $modele,
  $outputlangs = '',
  $hidedetails = 0,
  $hidedesc = 0,
  $hideref = 0 
)

Create object on disk.

Parameters
string$modeleforce le modele a utiliser ('' to not force)
Translate$outputlangsObject langs to use for output
int$hidedetailsHide details of lines
int$hidedescHide description
int$hiderefHide ref
Returns
int 0 if KO, 1 if OK

Definition at line 1079 of file mouvementstock.class.php.

◆ get_origin()

MouvementStock::get_origin (   $fk_origin,
  $origintype 
)

Return Url link of origin object.

Parameters
int$fk_originId origin
int$origintypeType origin
Returns
string

Definition at line 888 of file mouvementstock.class.php.

◆ getLibStatut()

MouvementStock::getLibStatut (   $mode = 0)

Return label statut.

Parameters
int$mode0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
Returns
string Label of status

Definition at line 1030 of file mouvementstock.class.php.

◆ getNomUrl()

MouvementStock::getNomUrl (   $withpicto = 0,
  $option = '',
  $notooltip = 0,
  $maxlen = 24,
  $morecss = '' 
)

Return a link (with optionaly the picto) Use this->id,this->lastname, this->firstname.

Parameters
int$withpictoInclude picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
string$optionOn what the link point to
integer$notooltip1=Disable tooltip
int$maxlenMax length of visible user name
string$morecssAdd more css on link
Returns
string String with URL

Definition at line 997 of file mouvementstock.class.php.

◆ initAsSpecimen()

MouvementStock::initAsSpecimen ( )

Initialise an instance with random values.

Used to build previews or test instances. id must be 0 if object instance is a specimen.

Returns
void

Definition at line 976 of file mouvementstock.class.php.

◆ LibStatut()

MouvementStock::LibStatut (   $mode = 0)

Renvoi le libelle d'un status donne.

Parameters
int$mode0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
Returns
string Label of status

Definition at line 1042 of file mouvementstock.class.php.

◆ livraison()

MouvementStock::livraison (   $user,
  $fk_product,
  $entrepot_id,
  $qty,
  $price = 0,
  $label = '',
  $datem = '',
  $eatby = '',
  $sellby = '',
  $batch = '',
  $id_product_batch = 0 
)

Decrease stock for product and subproducts.

Parameters
User$userObject user
int$fk_productId product
int$entrepot_idWarehouse id
int$qtyQuantity
int$pricePrice
string$labelLabel of stock movement
string$datemForce date of movement
date$eatbyeat-by date
date$sellbysell-by date
string$batchbatch number
int$id_product_batchId product_batch
Returns
int <0 if KO, >0 if OK

Definition at line 715 of file mouvementstock.class.php.

◆ reception()

MouvementStock::reception (   $user,
  $fk_product,
  $entrepot_id,
  $qty,
  $price = 0,
  $label = '',
  $eatby = '',
  $sellby = '',
  $batch = '' 
)

Increase stock for product and subproducts.

Parameters
User$userObject user
int$fk_productId product
int$entrepot_idWarehouse id
int$qtyQuantity
int$pricePrice
string$labelLabel of stock movement
date$eatbyeat-by date
date$sellbysell-by date
string$batchbatch number
Returns
int <0 if KO, >0 if OK

Definition at line 738 of file mouvementstock.class.php.

References _create().

◆ setOrigin()

MouvementStock::setOrigin (   $origin_element,
  $origin_id 
)

Set attribute origin to object.

Parameters
string$origin_elementtype of element
int$origin_idid of element
Returns
void

Definition at line 949 of file mouvementstock.class.php.


The documentation for this class was generated from the following file: