28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $element =
'intracommreport';
44 public $table_element =
'intracommreport';
49 public $fk_element =
'fk_intracommreport';
54 public $picto =
'intracommreport';
57 const STATUS_DRAFT = 0;
58 const STATUS_VALIDATED = 1;
59 const STATUS_CANCELED = 9;
106 public $fields = array(
107 "rowid" => array(
"type" =>
"integer",
"label" =>
"TechnicalID",
"enabled" => 1,
'position' => 10,
'notnull' => 1,
"visible" =>
"0",),
108 "ref" => array(
"type" =>
"varchar(30)",
"label" =>
"Ref",
"enabled" => 1,
'position' => 15,
'notnull' => 1,
"visible" => 1,
"csslist" =>
"tdoverflowmax150",
"showoncombobox" => 1,),
109 "type_declaration" => array(
"type" =>
"varchar(32)",
"label" =>
"TypeOfDeclaration",
"enabled" => 1,
'position' => 25,
'notnull' => 0,
"visible" => 1,
'arrayofkeyval' => array(
"deb" =>
"DEB",
"des" =>
"DES")),
110 "periods" => array(
"type" =>
"varchar(32)",
"label" =>
"Periods",
"enabled" => 1,
'position' => 30,
'notnull' => 0,
"visible" => -1,),
111 "mode" => array(
"type" =>
"varchar(32)",
"label" =>
"Mode",
"enabled" => 1,
'position' => 35,
'notnull' => 0,
"visible" => -1,),
112 "content_xml" => array(
"type" =>
"text",
"label" =>
"Contentxml",
"enabled" => 1,
'position' => 40,
'notnull' => 0,
"visible" => -1,),
113 "type_export" => array(
"type" =>
"varchar(10)",
"label" =>
"TypeOfExport",
"enabled" => 1,
'position' => 45,
'notnull' => 0,
"visible" => -1,
'arrayofkeyval' => array(
"in" =>
"Input",
"out" =>
"Output")),
114 "datec" => array(
"type" =>
"datetime",
"label" =>
"DateCreation",
"enabled" => 1,
'position' => 50,
'notnull' => 0,
"visible" => -1,),
115 "tms" => array(
"type" =>
"timestamp",
"label" =>
"DateModification",
"enabled" => 1,
'position' => 55,
'notnull' => 1,
"visible" => -1,),
128 public $type_declaration;
174 public $declaration_number;
179 public $numero_declaration;
203 $this->ismultientitymanaged = 1;
204 $this->isextrafieldmanaged = 1;
207 if (!
getDolGlobalInt(
'MAIN_SHOW_TECHNICAL_ID') && isset($this->fields[
'rowid']) && !empty($this->fields[
'ref'])) {
208 $this->fields[
'rowid'][
'visible'] = 0;
210 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
211 $this->fields[
'entity'][
'enabled'] = 0;
221 foreach ($this->fields as $key => $val) {
222 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
223 unset($this->fields[$key]);
228 if (is_object($langs)) {
229 foreach ($this->fields as $key => $val) {
230 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
231 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
232 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
238 $this->type_export =
'deb';
248 public function create($user, $notrigger = 0)
254 return $resultcreate;
266 public function fetch($id, $ref =
null, $noextrafields = 0, $nolines = 0)
268 $result = $this->
fetchCommon($id, $ref,
'', $noextrafields);
269 if ($result > 0 && !empty($this->table_element_line) && empty($nolines)) {
270 $this->fetchLines($noextrafields);
282 public function delete($user, $notrigger = 0)
296 public function getXML($mode =
'O', $type =
'introduction', $period_reference =
'')
301 $party_id = substr(strtr(
$mysoc->tva_intra ??
'', array(
' ' =>
'')), 0, 4).$mysoc->idprof2;
302 $declarant = substr(
$mysoc->managers, 0, 14);
307 $e =
new SimpleXMLElement(
'<?xml version="1.0" encoding="utf-8" standalone="yes"?><INSTAT></INSTAT>');
309 $envelope = $e->addChild(
'Envelope');
310 $envelope->addChild(
'envelopeId',
getDolGlobalString(
'INTRACOMMREPORT_NUM_AGREMENT'));
311 $date_time = $envelope->addChild(
'DateTime');
312 $date_time->addChild(
'date',
date(
'Y-m-d'));
313 $date_time->addChild(
'time',
date(
'H:i:s'));
314 $party = $envelope->addChild(
'Party');
315 $party->addAttribute(
'partyType',
$conf->global->INTRACOMMREPORT_TYPE_ACTEUR);
316 $party->addAttribute(
'partyRole',
$conf->global->INTRACOMMREPORT_ROLE_ACTEUR);
317 $party->addChild(
'partyId', $party_id);
318 $party->addChild(
'partyName', $declarant);
319 $envelope->addChild(
'softwareUsed',
'Dolibarr');
320 $declaration = $envelope->addChild(
'Declaration');
321 $declaration->addChild(
'declarationId', $id_declaration);
322 $declaration->addChild(
'referencePeriod', $period_reference);
328 $declaration->addChild(
'PSIId', $psiId);
329 $function = $declaration->addChild(
'Function');
330 $functionCode = $function->addChild(
'functionCode', $mode);
331 $declaration->addChild(
'declarationTypeCode',
getDolGlobalString(
'INTRACOMMREPORT_NIV_OBLIGATION_'.strtoupper($type)));
332 $declaration->addChild(
'flowCode', ($type ==
'introduction' ?
'A' :
'D'));
333 $declaration->addChild(
'currencyCode',
$conf->global->MAIN_MONNAIE);
336 $res = $this->
addItemsFact($declaration, $type, $period_reference);
338 $this->errors = array_unique($this->errors);
355 public function getXMLDes($period_year, $period_month, $type_declaration =
'expedition')
359 $e =
new SimpleXMLElement(
'<?xml version="1.0" encoding="utf-8" ?><fichier_des></fichier_des>');
361 $declaration_des = $e->addChild(
'declaration_des');
362 $declaration_des->addChild(
'num_des', self::getDeclarationNumber($this->numero_declaration));
363 $declaration_des->addChild(
'num_tvaFr',
$mysoc->tva_intra ??
'');
364 $declaration_des->addChild(
'mois_des', (
string) $period_month);
365 $declaration_des->addChild(
'an_des', (
string) $period_year);
368 $res = $this->
addItemsFact($declaration_des, $type_declaration, $period_year.
'-'.$period_month,
'des');
370 $this->errors = array_unique($this->errors);
388 public function addItemsFact(&$declaration, $type, $period_reference, $exporttype =
'deb')
390 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
394 $resql = $this->db->query($sql);
399 if ($this->db->num_rows($resql) <= 0) {
400 $this->errors[] =
'No data for this period';
404 $categ_fraisdeport =
null;
405 if ($exporttype ==
'deb' &&
getDolGlobalInt(
'INTRACOMMREPORT_CATEG_FRAISDEPORT') > 0) {
406 $categ_fraisdeport =
new Categorie($this->db);
407 $categ_fraisdeport->fetch(
getDolGlobalInt(
'INTRACOMMREPORT_CATEG_FRAISDEPORT'));
408 $TLinesFraisDePort = array();
411 while ($res = $this->db->fetch_object($resql)) {
412 if ($exporttype ==
'des') {
415 if (empty($res->fk_pays)) {
417 $this->errors[] =
'Country not filled in for the third party <a href="'.dol_buildpath(
'/societe/soc.php', 1).
'?socid='.$res->id_client.
'">'.$res->nom.
'</a>';
419 if (
getDolGlobalInt(
'INTRACOMMREPORT_CATEG_FRAISDEPORT') > 0 && $categ_fraisdeport->containsObject(
'product', $res->id_prod)) {
420 $TLinesFraisDePort[] = $res;
422 $this->
addItemXMl($declaration, $res, $i,
'');
430 if (!empty($TLinesFraisDePort) && $categ_fraisdeport !==
null) {
431 $this->
addItemFraisDePort($declaration, $TLinesFraisDePort, $type, $categ_fraisdeport, $i);
434 if (count($this->errors) > 0) {
454 if ($type ==
'expedition' || $exporttype ==
'des') {
455 $sql =
"SELECT f.ref as refinvoice, f.total_ht";
457 $table_extraf =
'facture_extrafields';
458 $tabledet =
'facturedet';
459 $field_link =
'fk_facture';
461 $sql =
"SELECT f.ref_supplier as refinvoice, f.total_ht";
462 $table =
'facture_fourn';
463 $table_extraf =
'facture_fourn_extrafields';
464 $tabledet =
'facture_fourn_det';
465 $field_link =
'fk_facture_fourn';
467 list($year, $month) = explode(
'-', $period_reference);
468 $period_end_of_month_day = cal_days_in_month(CAL_GREGORIAN, (
int) $month, (
int) $year);
470 $sql .=
", l.fk_product, l.qty
471 , p.weight, p.rowid as id_prod, p.customcode
472 , s.rowid as id_client, s.nom, s.zip, s.fk_pays, s.tva_intra
475 FROM ".MAIN_DB_PREFIX.$tabledet.
" l
476 INNER JOIN ".MAIN_DB_PREFIX.$table.
" f ON (f.rowid = l.".$this->db->escape($field_link).
")
477 LEFT JOIN ".MAIN_DB_PREFIX.$table_extraf.
" ext ON (ext.fk_object = f.rowid)
478 INNER JOIN ".MAIN_DB_PREFIX.
"product p ON (p.rowid = l.fk_product)
479 INNER JOIN ".MAIN_DB_PREFIX.
"societe s ON (s.rowid = f.fk_soc)
480 LEFT JOIN ".MAIN_DB_PREFIX.
"c_country c ON (c.rowid = s.fk_pays)
481 WHERE f.fk_statut > 0
482 AND l.product_type = ".($exporttype ==
"des" ? 1 : 0).
"
483 AND f.entity = ".((
int)
$conf->entity).
"
484 AND (s.fk_pays <> ".((
int)
$mysoc->country_id).
" OR s.fk_pays IS NULL)
485 AND f.datef BETWEEN '".$this->db->escape((
string) $period_reference).
"-01' AND '".$this->db->escape((
string) $period_reference).
"-".((
int) $period_end_of_month_day).
"'";
499 public function addItemXMl(&$declaration, &$res, $i, $code_douane_spe =
'')
501 $item = $declaration->addChild(
'Item');
502 $item->addChild(
'itemNumber', (
string) $i);
503 $cn8 = $item->addChild(
'CN8');
504 if (empty($code_douane_spe)) {
505 $code_douane = $res->customcode;
507 $code_douane = $code_douane_spe;
509 $cn8->addChild(
'CN8Code', $code_douane);
510 $item->addChild(
'MSConsDestCode', $res->code);
511 $item->addChild(
'countryOfOriginCode', substr($res->zip, 0, 2));
512 $item->addChild(
'netMass', (
string) round($res->weight * $res->qty));
513 $item->addChild(
'quantityInSU', (
string) $res->qty);
514 $item->addChild(
'invoicedAmount', (
string) round($res->total_ht));
516 if (!empty($res->tva_intra)) {
517 $item->addChild(
'partnerId', $res->tva_intra);
519 $item->addChild(
'statisticalProcedureCode',
'11');
520 $nature_of_transaction = $item->addChild(
'NatureOfTransaction');
521 $nature_of_transaction->addChild(
'natureOfTransactionACode',
'1');
522 $nature_of_transaction->addChild(
'natureOfTransactionBCode',
'1');
523 $item->addChild(
'modeOfTransportCode', $res->mode_transport);
524 $item->addChild(
'regionCode', substr($res->zip, 0, 2));
537 $item = $declaration->addChild(
'ligne_des');
538 $item->addChild(
'numlin_des', (
string) $i);
539 $item->addChild(
'valeur', (
string) round($res->total_ht));
540 $item->addChild(
'partner_des', $res->tva_intra);
553 public function addItemFraisDePort(&$declaration, &$TLinesFraisDePort, $type, &$categ_fraisdeport, $i)
557 if ($type ==
'expedition') {
559 $tabledet =
'facturedet';
560 $field_link =
'fk_facture';
563 $table =
'facture_fourn';
564 $tabledet =
'facture_fourn_det';
565 $field_link =
'fk_facture_fourn';
566 $more_sql =
'f.ref_supplier';
569 foreach ($TLinesFraisDePort as $res) {
570 $sql =
"SELECT p.customcode
571 FROM ".MAIN_DB_PREFIX.$tabledet.
" d
572 INNER JOIN ".MAIN_DB_PREFIX.$table.
" f ON (f.rowid = d.".$this->db->escape($field_link).
")
573 INNER JOIN ".MAIN_DB_PREFIX.
"product p ON (p.rowid = d.fk_product)
574 WHERE d.fk_product IS NOT NULL
575 AND f.entity = ".((int)
$conf->entity).
"
576 AND ".$more_sql.
" = '".$this->db->escape($res->refinvoice).
"'
579 SELECT MAX(d.total_ht)
580 FROM ".MAIN_DB_PREFIX.$tabledet.
" d
581 INNER JOIN ".MAIN_DB_PREFIX.$table.
" f ON (f.rowid = d.".$this->db->escape($field_link).
")
582 WHERE d.fk_product IS NOT NULL
583 AND ".$more_sql.
" = '".$this->db->escape($res->refinvoice).
"'
584 AND d.fk_product NOT IN
587 FROM ".MAIN_DB_PREFIX.
"categorie_product
588 WHERE fk_categorie = ".((int) $categ_fraisdeport->id).
"
592 $resql = $this->db->query($sql);
593 $ress = $this->db->fetch_object($resql);
595 $this->
addItemXMl($declaration, $res, $i, $ress->customcode);
608 $sql =
"SELECT MAX(numero_declaration) as max_declaration_number";
609 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
610 $sql .=
" WHERE exporttype = '".$this->db->escape($this->type_export).
"'";
611 $resql = $this->db->query($sql);
614 $res = $this->db->fetch_object($resql);
617 return (
string) ($res !==
null ? ($res->max_declaration_number + 1) :
'');
628 return str_pad($number, 6,
'0', STR_PAD_LEFT);
643 $name = $this->period.
'.xml';
644 $fname =
$conf->intracommreport->dir_temp.
'/'.$name;
646 $f = fopen($fname,
'w+');
647 fwrite($f, $content_xml);
650 header(
'Content-Description: File Transfer');
651 header(
'Content-Type: application/xml');
652 header(
'Content-Disposition: attachment; filename="'.$name.
'"');
653 header(
'Expires: 0');
654 header(
'Cache-Control: must-revalidate');
655 header(
'Pragma: public');
656 header(
'Content-Length: '.filesize($fname));
673 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
675 global
$conf, $langs, $hookmanager;
677 if (!empty(
$conf->dol_no_mouse_hover)) {
684 'objecttype' => $this->element.($this->module ?
'@'.$this->module :
''),
687 $classfortooltip =
'classfortooltip';
690 $classfortooltip =
'classforajaxtooltip';
691 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
697 $url =
dol_buildpath(
'/intracommreport/card.php', 1).
'?id='.$this->id;
699 if ($option !==
'nolink') {
701 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
702 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
703 $add_save_lastsearch_values = 1;
705 if ($url && $add_save_lastsearch_values) {
706 $url .=
'&save_lastsearch_values=1';
711 if (empty($notooltip)) {
713 $label = $langs->trans(
"ShowMyObject");
714 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
716 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
717 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
719 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
722 if ($option ==
'nolink' || empty($url)) {
723 $linkstart =
'<span';
725 $linkstart =
'<a href="'.$url.
'"';
727 $linkstart .= $linkclose.
'>';
728 if ($option ==
'nolink' || empty($url)) {
729 $linkend =
'</span>';
734 $result .= $linkstart;
736 if (empty($this->showphoto_on_popup)) {
738 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
742 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
744 list($class, $module) = explode(
'@', $this->picto);
747 $filename = $filearray[0][
'name'];
748 if (!empty($filename)) {
749 $pospoint = strpos($filearray[0][
'name'],
'.');
751 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
753 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.
'" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.
$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div></div>';
755 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.
$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div>';
760 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
765 if ($withpicto != 2) {
766 $result .= $this->ref;
772 global $action, $hookmanager;
773 $hookmanager->initHooks(array($this->element.
'dao'));
774 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
775 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
777 $result = $hookmanager->resPrint;
779 $result .= $hookmanager->resPrint;
794 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
796 $return =
'<div class="box-flex-item box-flex-grow-zero">';
797 $return .=
'<div class="info-box info-box-sm">';
798 $return .=
'<span class="info-box-icon bg-infobox-action">';
800 $return .=
'</span>';
801 $return .=
'<div class="info-box-content">';
802 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
803 if ($selected >= 0) {
804 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
806 if (property_exists($this,
'label')) {
807 $return .=
' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.
'</div>';
809 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
810 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
812 if (method_exists($this,
'getLibStatut')) {
813 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=0)
Create object in the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
getTooltipContentArray($params)
Return array of data to show into a tooltip.
Class to manage Dolibarr database access.
Class to manage intracomm report.
static getDeclarationNumber($number)
Verify declaration number.
addItemsFact(&$declaration, $type, $period_reference, $exporttype='deb')
Add line from invoice.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
const TYPE_DEB
DEB - Product.
const TYPE_DES
DES - Service.
__construct(DoliDB $db)
Constructor.
fetch($id, $ref=null, $noextrafields=0, $nolines=0)
Function fetch.
addItemXMl(&$declaration, &$res, $i, $code_douane_spe='')
Add item for DEB.
getXML($mode='O', $type='introduction', $period_reference='')
Generate XML file.
addItemXMlDes($declaration, &$res, $i)
Add item for DES.
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
addItemFraisDePort(&$declaration, &$TLinesFraisDePort, $type, &$categ_fraisdeport, $i)
This function adds an item by retrieving the customs code of the product with the highest amount in t...
getNextDeclarationNumber()
Return next reference of declaration not already used (or last reference)
getSQLFactLines($type, $period_reference, $exporttype='deb')
Add invoice line.
generateXMLFile($content_xml)
Generate XML file.
create($user, $notrigger=0)
Function create.
getXMLDes($period_year, $period_month, $type_declaration='expedition')
Generate XMLDes file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date