From d54c1aca01f1da9bfdebee15f601201d9093ce2c Mon Sep 17 00:00:00 2001 From: a-schild Date: Wed, 22 May 2019 10:01:25 +0200 Subject: [PATCH 1/8] Add accountancy export option for Sage50 Swiss --- .../class/accountancyexport.class.php | 178 +++++++++++++++++- 1 file changed, 177 insertions(+), 1 deletion(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 8ca2de4a132..08ff6689946 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -9,7 +9,7 @@ * Copyright (C) 2013-2017 Olivier Geffroy * Copyright (C) 2017 Elarifr. Ari Elbaz * Copyright (C) 2017-2019 Frédéric France - + * Copyright (C) 2017 André Schild * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -51,6 +51,7 @@ class AccountancyExport public static $EXPORT_TYPE_AGIRIS = 9; public static $EXPORT_TYPE_FEC = 11; public static $EXPORT_TYPE_OPENCONCERTO = 12; + public static $EXPORT_TYPE_SAGE50_SWISS = 13; /** @@ -106,6 +107,7 @@ class AccountancyExport self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'), self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'), self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'), + self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'), ); } @@ -130,6 +132,7 @@ class AccountancyExport self::$EXPORT_TYPE_AGIRIS => 'agiris', self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto', self::$EXPORT_TYPE_FEC => 'fec', + self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch', ); return $formatcode[$type]; @@ -194,6 +197,10 @@ class AccountancyExport 'label' => $langs->trans('Modelcsv_openconcerto'), 'ACCOUNTING_EXPORT_FORMAT' => 'csv', ), + self::$EXPORT_TYPE_SAGE50_SWISS => array( + 'label' => $langs->trans('Modelcsv_Sage50_Swiss'), + 'ACCOUNTING_EXPORT_FORMAT' => 'csv', + ), ), 'cr'=> array ( '1' => $langs->trans("Unix"), @@ -261,6 +268,9 @@ class AccountancyExport case self::$EXPORT_TYPE_FEC : $this->exportFEC($TData); break; + case self::$EXPORT_TYPE_SAGE50_SWISS : + $this->exportSAGE50SWISS($TData); + break; default: $this->errors[] = $langs->trans('accountancy_error_modelnotfound'); break; @@ -757,6 +767,157 @@ class AccountancyExport } } + /** + * Export format : SAGE50SWISS + * + * + * https://onlinehelp.sageschweiz.ch/default.aspx?tabid=19984 + * http://media.topal.ch/Public/Schnittstellen/TAF/Specification/Sage50-TAF-format.pdf + * + * @param array $objectLines data + * + * @return void + */ + public function exportSAGE50SWISS($objectLines) { + + // SAGE50SWISS + $this->separator = ','; + $this->end_line = "\r\n"; + + // Print header line + print "Blg,Datum,Kto,S/H,Grp,GKto,SId,SIdx,KIdx,BTyp,MTyp,Code,Netto,Steuer,FW-Betrag,Tx1,Tx2,PkKey,OpId,Flag"; + print $this->end_line; + $thisPieceNum= ""; + $thisPieceAccountNr= ""; + $aSize= count($objectLines); + foreach ( $objectLines as $aIndex=>$line ) { + + $sammelBuchung= false; + if ($aIndex-2 >= 0 && $objectLines[$aIndex-2]->piece_num == $line->piece_num) + { + $sammelBuchung= true; + } + else if ($aIndex+2 < $aSize && $objectLines[$aIndex+2]->piece_num == $line->piece_num) + { + $sammelBuchung= true; + } + else if ($aIndex+1 < $aSize + && $objectLines[$aIndex+1]->piece_num == $line->piece_num + && $aIndex-1 < $aSize + && $objectLines[$aIndex-1]->piece_num == $line->piece_num + ) + { + $sammelBuchung= true; + } + + //Blg + print $line->piece_num . $this->separator; + + // Datum + $date = dol_print_date($line->doc_date, '%d.%m.%Y'); + print $date . $this->separator; + + // Kto + print length_accountg($line->numero_compte) . $this->separator; + // S/H + if ($line->sens == 'D') + { + print 'S' . $this->separator; + } + else + { + print 'H' . $this->separator; + } + //Grp + print self::trunc($line->code_journal,1 ) . $this->separator; + // GKto + if (empty($line->code_tiers )) + { + if ($line->piece_num == $thisPieceNum) + { + print length_accounta($thisPieceAccountNr) . $this->separator; + } + else + { + print "div" . $this->separator; + } + } + else + { + print length_accounta($line->code_tiers) . $this->separator; + } + //SId + print $this->separator; + //SIdx + print "0" . $this->separator; + //KIdx + print "0" . $this->separator; + //BTyp + print "0" . $this->separator; + + //MTyp 1=Fibu Einzelbuchung 2=Sammebuchung + if ($sammelBuchung) + { + print "2" . $this->separator; + } + else + { + print "1" . $this->separator; + } + // Code + print '""' . $this->separator; + // Netto + if ($line->montant >= 0) + { + print $line->montant . $this->separator; + } + else + { + print $line->montant*-1 . $this->separator; + } + // Steuer + print "0.00" . $this->separator; + // FW-Betrag + print "0.00" . $this->separator; + // Tx1 + $line1= self::toAnsi($line->label_compte, 29); + if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) + { + $line1= ""; + } + $line2= self::toAnsi($line->doc_ref, 29); + if (strlen($line1) == 0) + { + $line1= $line2; + $line2= ""; + } + if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) + { + $line1= $line1 . ' / ' . $line2; + $line2= ""; + } + + print '"' . self::toAnsi( $line1 ). '"' . $this->separator; + // Tx2 + print '"' . self::toAnsi( $line2 ). '"' . $this->separator; + //PkKey + print "0" . $this->separator; + //OpId + print $this->separator; + + // Flag + print "0"; + + print $this->end_line; + + if ($line->piece_num !== $thisPieceNum) + { + $thisPieceNum= $line->piece_num; + $thisPieceAccountNr= $line->numero_compte; + } + } + } + /** * * @param string $str data @@ -767,4 +928,19 @@ class AccountancyExport { return dol_trunc($str, $size, 'right', 'UTF-8', 1); } + + /** + * + * @param unknown $str data + * @param integer $size data + */ + public static function toAnsi($str, $size= -1) { + $retVal= dol_string_nohtmltag($str, 1, 'Windows-1251'); + if ($retVal >= 0 && $size >= 0) + { + $retVal= mb_substr($retVal, 0, $size, 'Windows-1251'); + } + return $retVal; + } + } From 445a66ed216d269fac136fb57deb686913b7057d Mon Sep 17 00:00:00 2001 From: a-schild Date: Wed, 22 May 2019 10:21:35 +0200 Subject: [PATCH 2/8] Added sage50 swiss translation texts for EN/DE/FR/IT --- htdocs/langs/de_DE/accountancy.lang | 1 + htdocs/langs/en_US/accountancy.lang | 1 + htdocs/langs/fr_FR/accountancy.lang | 1 + htdocs/langs/it_IT/accountancy.lang | 1 + 4 files changed, 4 insertions(+) diff --git a/htdocs/langs/de_DE/accountancy.lang b/htdocs/langs/de_DE/accountancy.lang index 2195ca499db..c15b3b1388a 100644 --- a/htdocs/langs/de_DE/accountancy.lang +++ b/htdocs/langs/de_DE/accountancy.lang @@ -290,6 +290,7 @@ Modelcsv_cogilog=Export for Cogilog Modelcsv_agiris=Export for Agiris Modelcsv_configurable=Konfigurierbarer CSV Export Modelcsv_FEC=Export FEC (Art. L47 A) (Test) +Modelcsv_Sage50_Swiss=Export für Sage 50 Schweiz ChartofaccountsId=Kontenplan ID ## Tools - Init accounting account on product / service diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 25b8f8d11aa..20b9862e187 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -292,6 +292,7 @@ Modelcsv_agiris=Export for Agiris Modelcsv_openconcerto=Export for OpenConcerto (Test) Modelcsv_configurable=Export CSV Configurable Modelcsv_FEC=Export FEC (Art. L47 A) +Modelcsv_Sage50_Swiss=Export for Sage 50 Switzerland ChartofaccountsId=Chart of accounts Id ## Tools - Init accounting account on product / service diff --git a/htdocs/langs/fr_FR/accountancy.lang b/htdocs/langs/fr_FR/accountancy.lang index 638afa65361..499ffdf4f69 100644 --- a/htdocs/langs/fr_FR/accountancy.lang +++ b/htdocs/langs/fr_FR/accountancy.lang @@ -291,6 +291,7 @@ Modelcsv_cogilog=Export vers Cogilog Modelcsv_agiris=Export vers Agiris Modelcsv_configurable=Export configurable Modelcsv_FEC=Exportation FEC (Art. L47 A) (Test) +Modelcsv_Sage50_Swiss=Export vers Sage 50 Suisse ChartofaccountsId=Id plan comptable ## Tools - Init accounting account on product / service diff --git a/htdocs/langs/it_IT/accountancy.lang b/htdocs/langs/it_IT/accountancy.lang index afd72acf1b1..5b721b13c13 100644 --- a/htdocs/langs/it_IT/accountancy.lang +++ b/htdocs/langs/it_IT/accountancy.lang @@ -290,6 +290,7 @@ Modelcsv_cogilog=Export for Cogilog Modelcsv_agiris=Export for Agiris Modelcsv_configurable=Export CSV Configurable Modelcsv_FEC=Export FEC (Art. L47 A) (Test) +Modelcsv_Sage50_Swiss=Export for Sage 50 Switzerland ChartofaccountsId=Id Piano dei Conti ## Tools - Init accounting account on product / service From 5f25398c5cc36a3e8715e62615868e1cf9b4e86e Mon Sep 17 00:00:00 2001 From: a-schild Date: Wed, 22 May 2019 10:34:39 +0200 Subject: [PATCH 3/8] Corrected code format and documentation --- .../class/accountancyexport.class.php | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 08ff6689946..638d03eca73 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -778,8 +778,8 @@ class AccountancyExport * * @return void */ - public function exportSAGE50SWISS($objectLines) { - + public function exportSAGE50SWISS($objectLines) + { // SAGE50SWISS $this->separator = ','; $this->end_line = "\r\n"; @@ -790,18 +790,18 @@ class AccountancyExport $thisPieceNum= ""; $thisPieceAccountNr= ""; $aSize= count($objectLines); - foreach ( $objectLines as $aIndex=>$line ) { - + foreach ( $objectLines as $aIndex=>$line ) + { $sammelBuchung= false; if ($aIndex-2 >= 0 && $objectLines[$aIndex-2]->piece_num == $line->piece_num) { $sammelBuchung= true; } - else if ($aIndex+2 < $aSize && $objectLines[$aIndex+2]->piece_num == $line->piece_num) + elseif ($aIndex+2 < $aSize && $objectLines[$aIndex+2]->piece_num == $line->piece_num) { $sammelBuchung= true; } - else if ($aIndex+1 < $aSize + elseif ($aIndex+1 < $aSize && $objectLines[$aIndex+1]->piece_num == $line->piece_num && $aIndex-1 < $aSize && $objectLines[$aIndex-1]->piece_num == $line->piece_num @@ -829,9 +829,9 @@ class AccountancyExport print 'H' . $this->separator; } //Grp - print self::trunc($line->code_journal,1 ) . $this->separator; + print self::trunc($line->code_journal, 1) . $this->separator; // GKto - if (empty($line->code_tiers )) + if (empty($line->code_tiers)) { if ($line->piece_num == $thisPieceNum) { @@ -897,9 +897,9 @@ class AccountancyExport $line2= ""; } - print '"' . self::toAnsi( $line1 ). '"' . $this->separator; + print '"' . self::toAnsi($line1). '"' . $this->separator; // Tx2 - print '"' . self::toAnsi( $line2 ). '"' . $this->separator; + print '"' . self::toAnsi($line2). '"' . $this->separator; //PkKey print "0" . $this->separator; //OpId @@ -931,10 +931,12 @@ class AccountancyExport /** * - * @param unknown $str data - * @param integer $size data + * @param unknown $str Original string to encode and optionaly truncate + * @param integer $size trucate string after $size characters + * @return string String encoded in Windows-1251 charset */ - public static function toAnsi($str, $size= -1) { + public static function toAnsi($str, $size = -1) + { $retVal= dol_string_nohtmltag($str, 1, 'Windows-1251'); if ($retVal >= 0 && $size >= 0) { @@ -942,5 +944,4 @@ class AccountancyExport } return $retVal; } - } From a823882f76e9a3e68110ce4a3fd84547a86df587 Mon Sep 17 00:00:00 2001 From: a-schild Date: Wed, 22 May 2019 10:57:59 +0200 Subject: [PATCH 4/8] Some more formatting fixes --- htdocs/accountancy/class/accountancyexport.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 638d03eca73..d1d6d4f8b51 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -790,7 +790,7 @@ class AccountancyExport $thisPieceNum= ""; $thisPieceAccountNr= ""; $aSize= count($objectLines); - foreach ( $objectLines as $aIndex=>$line ) + foreach ($objectLines as $aIndex=>$line) { $sammelBuchung= false; if ($aIndex-2 >= 0 && $objectLines[$aIndex-2]->piece_num == $line->piece_num) From fff133b8a5b984d0979cfd205c58a2767d3c21f6 Mon Sep 17 00:00:00 2001 From: a-schild Date: Wed, 22 May 2019 11:40:58 +0200 Subject: [PATCH 5/8] PSR_2 Format of code --- .../class/accountancyexport.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index d1d6d4f8b51..1ef500fcf6b 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -779,7 +779,7 @@ class AccountancyExport * @return void */ public function exportSAGE50SWISS($objectLines) - { + { // SAGE50SWISS $this->separator = ','; $this->end_line = "\r\n"; @@ -915,7 +915,7 @@ class AccountancyExport $thisPieceNum= $line->piece_num; $thisPieceAccountNr= $line->numero_compte; } - } + } } /** @@ -936,12 +936,12 @@ class AccountancyExport * @return string String encoded in Windows-1251 charset */ public static function toAnsi($str, $size = -1) - { + { $retVal= dol_string_nohtmltag($str, 1, 'Windows-1251'); - if ($retVal >= 0 && $size >= 0) - { - $retVal= mb_substr($retVal, 0, $size, 'Windows-1251'); - } - return $retVal; + if ($retVal >= 0 && $size >= 0) + { + $retVal= mb_substr($retVal, 0, $size, 'Windows-1251'); + } + return $retVal; } } From ab646450d64f363128946d39904eac10a3c5854b Mon Sep 17 00:00:00 2001 From: a-schild Date: Wed, 22 May 2019 17:03:49 +0200 Subject: [PATCH 6/8] Revert changes in DE/FR/IT languages, since they are generated/maintained via Transifex --- htdocs/langs/de_DE/accountancy.lang | 1 - htdocs/langs/fr_FR/accountancy.lang | 1 - htdocs/langs/it_IT/accountancy.lang | 1 - 3 files changed, 3 deletions(-) diff --git a/htdocs/langs/de_DE/accountancy.lang b/htdocs/langs/de_DE/accountancy.lang index c15b3b1388a..2195ca499db 100644 --- a/htdocs/langs/de_DE/accountancy.lang +++ b/htdocs/langs/de_DE/accountancy.lang @@ -290,7 +290,6 @@ Modelcsv_cogilog=Export for Cogilog Modelcsv_agiris=Export for Agiris Modelcsv_configurable=Konfigurierbarer CSV Export Modelcsv_FEC=Export FEC (Art. L47 A) (Test) -Modelcsv_Sage50_Swiss=Export für Sage 50 Schweiz ChartofaccountsId=Kontenplan ID ## Tools - Init accounting account on product / service diff --git a/htdocs/langs/fr_FR/accountancy.lang b/htdocs/langs/fr_FR/accountancy.lang index 499ffdf4f69..638afa65361 100644 --- a/htdocs/langs/fr_FR/accountancy.lang +++ b/htdocs/langs/fr_FR/accountancy.lang @@ -291,7 +291,6 @@ Modelcsv_cogilog=Export vers Cogilog Modelcsv_agiris=Export vers Agiris Modelcsv_configurable=Export configurable Modelcsv_FEC=Exportation FEC (Art. L47 A) (Test) -Modelcsv_Sage50_Swiss=Export vers Sage 50 Suisse ChartofaccountsId=Id plan comptable ## Tools - Init accounting account on product / service diff --git a/htdocs/langs/it_IT/accountancy.lang b/htdocs/langs/it_IT/accountancy.lang index 5b721b13c13..afd72acf1b1 100644 --- a/htdocs/langs/it_IT/accountancy.lang +++ b/htdocs/langs/it_IT/accountancy.lang @@ -290,7 +290,6 @@ Modelcsv_cogilog=Export for Cogilog Modelcsv_agiris=Export for Agiris Modelcsv_configurable=Export CSV Configurable Modelcsv_FEC=Export FEC (Art. L47 A) (Test) -Modelcsv_Sage50_Swiss=Export for Sage 50 Switzerland ChartofaccountsId=Id Piano dei Conti ## Tools - Init accounting account on product / service From 1c1b3c376eadff9bdc245716a7ad941d432d0499 Mon Sep 17 00:00:00 2001 From: Lionel VESSILLER Date: Thu, 23 May 2019 15:57:02 +0200 Subject: [PATCH 7/8] Fix check if order line is not in a shipment line before deleting --- htdocs/commande/class/commande.class.php | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index d2012870a31..6a5f333492e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -4051,6 +4051,33 @@ class OrderLine extends CommonOrderLine $error=0; + // check if order line is not in a shipment line before deleting + $sqlCheckShipmentLine = "SELECT"; + $sqlCheckShipmentLine .= " ed.rowid"; + $sqlCheckShipmentLine .= " FROM " . MAIN_DB_PREFIX . "expeditiondet ed"; + $sqlCheckShipmentLine .= " WHERE ed.fk_origin_line = " . $this->rowid; + + $resqlCheckShipmentLine = $this->db->query($sqlCheckShipmentLine); + if (!$resqlCheckShipmentLine) { + $error++; + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + } else { + $langs->load('errors'); + $num = $this->db->num_rows($resqlCheckShipmentLine); + if ($num > 0) { + $error++; + $objCheckShipmentLine = $this->db->fetch_object($resqlCheckShipmentLine); + $this->error = $langs->trans('ErrorRecordAlreadyExists') . ' : ' . $langs->trans('ShipmentLine') . ' ' . $objCheckShipmentLine->rowid; + $this->errors[] = $this->error; + } + $this->db->free($resqlCheckShipmentLine); + } + if ($error) { + dol_syslog(__METHOD__ . 'Error ; ' . $this->error, LOG_ERR); + return -1; + } + $this->db->begin(); $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid=".$this->rowid; From 99a96bffe21e4c87b8e3e3489bac844885ac2d35 Mon Sep 17 00:00:00 2001 From: andreubisquerra Date: Fri, 24 May 2019 08:36:43 +0200 Subject: [PATCH 8/8] Fix TakePOS terminal bug --- htdocs/takepos/takepos.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/takepos/takepos.php b/htdocs/takepos/takepos.php index dd2d6524f46..c0a37881cf9 100644 --- a/htdocs/takepos/takepos.php +++ b/htdocs/takepos/takepos.php @@ -573,8 +573,12 @@ $( document ).ready(function() { LoadProducts(0); Refresh(); global->TAKEPOS_NUM_TERMINALS!="1" && $_SESSION["takeposterminal"]=="") print "TerminalsDialog();"; + //IF NO TERMINAL SELECTED + if ($_SESSION["takeposterminal"]=="") + { + if ($conf->global->TAKEPOS_NUM_TERMINALS=="1") $_SESSION["takeposterminal"]=1; + else print "TerminalsDialog();"; + } ?> });