diff --git a/include/class/acc_ledger_history.class.php b/include/class/acc_ledger_history.class.php index 61f0c1ba4..30b25da97 100644 --- a/include/class/acc_ledger_history.class.php +++ b/include/class/acc_ledger_history.class.php @@ -26,6 +26,7 @@ */ require_once NOALYSS_INCLUDE."/class/acc_ledger_history_generic.class.php"; require_once NOALYSS_INCLUDE."/class/acc_ledger_history_sale.class.php"; +require_once NOALYSS_INCLUDE."/class/acc_ledger_history_purchase.class.php"; /** * @brief Display history of operation */ @@ -125,7 +126,7 @@ abstract class Acc_Ledger_History static function factory(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode) { // For Accounting writing , we use Acc_Ledger_History - if ($p_mode=="E") + if ($p_mode=="A") { $ret=new Acc_Ledger_History_Generic($cn, $pa_ledger, $p_from, $p_to, $p_mode); @@ -236,8 +237,8 @@ abstract class Acc_Ledger_History */ protected function prepare_reconcile_date() { - static $prepare=0; - if ($prepare==0) + $prepare=$this->db->is_prepare("reconcile_date"); + if ($prepare==FALSE) { $this->db->prepare('reconcile_date', 'select * @@ -256,7 +257,6 @@ abstract class Acc_Ledger_History from jrn_rapt where jra_concerned=$1)'); } - $prepare=1; } /** * display accounting of operations m_mode=A diff --git a/include/class/acc_ledger_history_purchase.class.php b/include/class/acc_ledger_history_purchase.class.php index 64b9b5556..715ffa052 100644 --- a/include/class/acc_ledger_history_purchase.class.php +++ b/include/class/acc_ledger_history_purchase.class.php @@ -21,6 +21,209 @@ /** * @file - * @brief + * @brief class Acc_Ledger_History_Purchase , list of operations */ -?> +require_once NOALYSS_INCLUDE."/class/acc_ledger_history.class.php"; + +/** + * @brief Display the operations for Purchase + */ +class Acc_Ledger_History_Purchase extends Acc_Ledger_History +{ + + private $data; //!< Contains rows from SQL + + public function __construct(\Database $cn, $pa_ledger, $p_from, $p_to, + $p_mode) + { + parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode); + } + + /** + * @brief display the accounting + */ + public function export_accounting_html() + { + $ledger_history=new Acc_Ledger_History_Generic($this->db, + $this->ma_ledger, $this->m_from, $this->m_to, $this->m_mode); + $ledger_history->export_accounting_html(); + } + + public function export_detail_html() + { + $own=new Noalyss_Parameter_Folder($this->db); + + $this->get_row(); + $this->add_vat_info(); + $this->prepare_reconcile_date(); + include NOALYSS_TEMPLATE."/acc_ledger_history_purchase_detail.php"; + } + + public function export_extended_html() + { + $this->get_row(); + $this->add_vat_info(); + $this->prepare_detail(); + $this->prepare_reconcile_date(); + include NOALYSS_TEMPLATE."/acc_ledger_history_purchase_extended.php"; + } + + /** + * @brief display in HTML following the mode + */ + function export_html() + { + switch ($this->m_mode) + { + case "E": + $this->export_extended_html(); + break; + case "D": + $this->export_detail_html(); + break; + case "L": + $this->export_oneline_html(); + break; + case "A": + $this->export_accounting_html(); + break; + default: + break; + } + } + + /** + * display in HTML one operation by line + */ + public function export_oneline_html() + { + $this->get_row(); + $this->prepare_reconcile_date(); + require_once NOALYSS_TEMPLATE.'/acc_ledger_history_purchase_oneline.php'; + } + + /** + * Get the rows from jrnx and quant* tables + * @param int $p_limit max of rows to returns + * @param int $p_offset the number of rows to skip + */ + public function get_row($p_limit=-1, $p_offset="") + { + $periode=sql_filter_per($this->db, $this->m_from, $this->m_to, 'p_id', + 'jr_tech_per'); + + $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:""; + + $ledger_list=join(",", $this->ma_ledger); + $sql=" + with row_sale as + (select qp_internal, + qp_supplier,sum(qp_price) as novat, + sum(qp_vat) as vat , + sum(qp_vat_sided) as tva_sided , + sum(qp_nd_amount) as noded_amount, + sum(qp_nd_tva) as noded_vat, + sum(qp_dep_priv) as private_amount + from + quant_purchase group by qp_supplier,qp_internal), + supplier_detail as ( + select x.f_id as f_id, + (select ad_value from fiche_detail where ad_id=1 and f_id=x.f_id) as name, + (select ad_value from fiche_detail where ad_id=32 and f_id=x.f_id) as first_name, + (select ad_value from fiche_detail where ad_id=23 and f_id=x.f_id) as qcode + from + fiche as x) + select + name, + first_name, + qcode, + jr_id, + jr_pj_number, + jr_date, + jr_date_paid, + jr_internal, + qp_supplier, + jrn.jr_comment, + jr_pj_name, + vat, + tva_sided, + novat, + noded_amount, + noded_vat, + private_amount, + novat+vat-tva_sided as tvac + from + jrn + join row_sale on (qp_internal=jr_internal) + join supplier_detail on (qp_supplier=f_id) + where + jr_def_id in ({$ledger_list}) + and {$periode} + {$cond_limite}"; + $this->data=$this->db->get_array($sql); + } + + /** + * @brief preprare the query for fetching the detailed VAT of an operation + * @staticvar int $prepare + */ + private function add_vat_info() + { + $prepare=$this->db->is_prepare("vat_infop"); + if ($prepare==0) + { + $this->db->prepare("vat_infop", + " + select + sum(qp_vat) vat_amount , + qp_vat_code + from + quant_purchase + where + qp_internal = $1 + group by qp_vat_code,qp_internal order by qp_vat_code"); + } + + $prepare=1; + $nb_row=count($this->data); + for ($i=0; $i<$nb_row; $i++) + { + $ret=$this->db->execute("vat_infop", + array($this->data[$i]["jr_internal"])); + $array=Database::fetch_all($ret); + $this->data[$i]["detail_vat"]=$array; + } + } + + /** + * Prepare the query for fetching detail of an operation + */ + private function prepare_detail() + { + + if ($this->db->is_prepare("detail_purchase")==FALSE) + { + $this->db->prepare("detail_purchase", + " + with card_name as + (select f_id,ad_value as name + from fiche_detail where ad_id=1), + card_qcode as + (select f_id,ad_value as qcode + from fiche_detail where ad_id=23) + select qp_price,qp_quantite,qp_vat,qp_vat_code,qp_unit,qp_vat_sided,name,qcode,tva_label, + qp_price+qp_vat-qp_vat_sided as tvac + from + quant_purchase + join jrnx using (j_id) + join card_name on (card_name.f_id=qp_fiche) + join card_qcode on (card_qcode.f_id=qp_fiche) + join tva_rate on ( qp_vat_code=tva_id) + where + qp_internal=$1 + + "); + } + } + +} diff --git a/include/class/acc_ledger_history_sale.class.php b/include/class/acc_ledger_history_sale.class.php index 217b1842e..4f1b2f6bf 100644 --- a/include/class/acc_ledger_history_sale.class.php +++ b/include/class/acc_ledger_history_sale.class.php @@ -71,12 +71,11 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History } /** * Prepare the query for fetching detail of an operation - * @staticvar int $prepare */ private function prepare_detail() { - static $prepare=0; - if ( $prepare == 0) + + if ( $this->db->is_prepare("detail_sale")== FALSE) { $this->db->prepare("detail_sale"," with card_name as @@ -98,7 +97,6 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History "); } - $prepare=1; } /** * Get the rows from jrnx and quant* tables @@ -161,8 +159,8 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History */ private function add_vat_info() { - static $prepare=0; - if ( $prepare==0) { + $prepare=$this->db->is_prepare("vat_info"); + if ( $prepare==FALSE) { $this->db->prepare("vat_info"," select sum(qs_vat) vat_amount , @@ -175,7 +173,6 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History } - $prepare=1; $nb_row=count($this->data); for ($i=0;$i<$nb_row;$i++) { @@ -215,7 +212,7 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History { $this->get_row(); $this->prepare_reconcile_date(); - require_once NOALYSS_TEMPLATE.'/acc_history_ledger_sale_oneline.php'; + require_once NOALYSS_TEMPLATE.'/acc_ledger_history_sale_oneline.php'; } diff --git a/include/impress_jrn.inc.php b/include/impress_jrn.inc.php index f35949503..a5b02b2ee 100644 --- a/include/impress_jrn.inc.php +++ b/include/impress_jrn.inc.php @@ -144,13 +144,15 @@ print td('Jusque ') . $w->input('to_periode', $periode_end); print ""; $a = array( array('value' => 'L', 'label' => _('Liste opérations')), - array('value' => 'E', 'label' => _('Ecriture comptable')), - array('value' => 'D', 'label' => _('Avec Détails opérations ')) + array('value' => 'E', 'label' => _('Liste détaillées opérations ')), + array('value' => 'A', 'label' => _('Ecriture comptable')), + array('value' => 'D', 'label' => _('Détails TVA')) ); $w->selected = 1; print ''; print ''; -$w->selected = (isset($simple)) ? $simple : '1'; +$simple=$http->get("p_simple","string","L"); +$w->selected = $simple; echo 'Style d\'impression '.Icon_Action::infobulle(32).'' . $w->input('p_simple', $a); print ""; @@ -169,7 +171,7 @@ echo '
'; if (isset($_REQUEST['bt_html'])) { // Type of report : listing=1 , Accounting writing=0, detail =2 - $simple=$http->get("p_simple","string"); + $jrn_id=$http->get("jrn_id","number"); /* diff --git a/include/template/acc_ledger_history_purchase_detail.php b/include/template/acc_ledger_history_purchase_detail.php new file mode 100644 index 000000000..ea39c3fc7 --- /dev/null +++ b/include/template/acc_ledger_history_purchase_detail.php @@ -0,0 +1,196 @@ + + +if (!defined('ALLOWED')) + die('Appel direct ne sont pas permis'); + +/** + * @file + * @brief Display one purchase operation on one line , with the sum of VAT, ND... + */ +?> + + + + + + + + + + + + + +MY_TVA_USE=='Y') + { + echo ''; + $a_Tva=$this->db->get_array("select tva_id,tva_label from tva_rate where tva_rate != 0.0000 order by tva_id"); + foreach($a_Tva as $line_tva) + { + $col_tva.=''; + } + } +echo $col_tva; +?> + + + +data as $line) { + $i++; + /* + * Get date of reconcile operation + */ + $ret_reconcile=$this->db->execute('reconcile_date',array($line['jr_id'])); + $class = ($i % 2 == 0) ? ' class="even" ' : ' class="odd" '; + echo ""; + + // Receipt number + echo ""; + + // Date + echo ""; + echo ""; + + // Internal with detail + echo ""; + + // find the tiers (normally in $Row ! + $tiers =HtmlInput::history_card($line['qp_supplier'],h($line['name'].' '.$line['first_name'])."[{$line['qcode']}]"); + echo td($tiers); + // Label + echo ""; + + // Private expense + $private_amount=($line['private_amount']==0)?"":nbm(round($line['private_amount'],2),2); + $tot['private_amount']=bcadd($tot['private_amount'], floatval($line['private_amount'])); + + // No deductible + $noded_amount=($line['noded_amount']==0)?"":nbm(round($line['noded_amount'],2),2); + $tot['noded_amount']=bcadd($tot['noded_amount'],round(floatval($line['noded_amount'])),2); + + // HTVA amount + echo ""; + $tot['htva']=bcadd($tot['htva'], round(floatval($line['novat']),2)); + + echo ""; + echo ""; + + //-------------------------------------------------------------------------- + // If VAT then display it + //-------------------------------------------------------------------------- + if ($own->MY_TVA_USE == 'Y' ) + { + $tva_dna=($line['noded_vat']==0)?"":nbm(round($line['noded_vat']),2); + $tot['tva_nd']=bcadd($tot['tva_nd'], round(floatval($line['noded_vat']),2)); + echo ""; + $a_tva_amount=array(); + + foreach ($line['detail_vat'] as $lineTVA) + { + foreach ($a_Tva as $idx=>$line_tva) + { + + if ($line_tva['tva_id'] == $lineTVA['qp_vat_code']) + { + $a=$line_tva['tva_id']; + $a_tva_amount[$a]=$lineTVA['vat_amount']; + } + } + } + foreach ($a_Tva as $line_tva) + { + $a=$line_tva['tva_id']; + if ( isset($a_tva_amount[$a]) && $a_tva_amount[$a] != 0) { + echo ''; + $tot['tva'][$a]=(isset($tot['tva'][$a]))?bcadd($tot['tva'][$a],round(floatval($a_tva_amount[$a]),2)):round(floatval($a_tva_amount[$a]),2); + } + else + printf(""); + } + } + + echo ''; + $tot['tvac']=bcadd($tot['tvac'], round($line['tvac'],2)); + /* + * If reconcile print them + */ + echo ''; + echo ""; +} +/** + * summary + */ +?> + + + + + + + + + + + MY_TVA_USE == 'Y' ): ?> + + + + + + + + + + + + + +
HTVAPrivéDNATVA NDTva '.$line_tva['tva_label'].'TVAC
" . h($line['jr_pj_number']) . "" . smaller_date($line['jr_date']) . "" . smaller_date($line['jr_date_paid']) . "" . HtmlInput::detail_op($line['jr_id'], $line['jr_internal']) . "" . h($line['jr_comment']) . "" . nbm(round($line['novat'],2),2) . "" .$private_amount . "" . $noded_amount . "" . $tva_dna. "'.nbm(round($a_tva_amount[$a],2)).''.nbm($line['tvac'],2).''; + $max=Database::num_row($ret_reconcile); + if ($max > 0) { + $sep=""; + for ($e=0;$e<$max;$e++) { + $row=Database::fetch_array($ret_reconcile, $e); + echo $sep.HtmlInput::detail_op($row['jr_id'],$row['jr_date'].' '. $row['jr_internal']); + $sep=' ,'; + } + } + echo '
+ + + +
\ No newline at end of file diff --git a/include/template/acc_ledger_history_purchase_extended.php b/include/template/acc_ledger_history_purchase_extended.php new file mode 100644 index 000000000..a30de3321 --- /dev/null +++ b/include/template/acc_ledger_history_purchase_extended.php @@ -0,0 +1,173 @@ + + + +/** + * @file + * @brief detail of the list of operation with VAT and items + */ +?> + + + + + + + + + + + + +data); +$tot_amount_novat=0; +$tot_amount_vat=0; +$tot_amount_tvac=0; +for ($i=0;$i<$nb_data;$i++): + $odd=' class="odd" '; + $tot_amount_novat=bcadd($tot_amount_novat,$this->data[$i]['novat']); + $tot_amount_vat=bcadd($tot_amount_vat,$this->data[$i]['vat']); + $tot_amount_vat=bcsub($tot_amount_vat,$this->data[$i]['tva_sided']); + $tot_amount_tvac=bcadd($tot_amount_tvac,$this->data[$i]['tvac']); +?> + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ data[$i]['jr_date']?> + + data[$i]['jr_date_paid']?> + + data[$i]['jr_pj_number']?> + + data[$i]['jr_id'], $this->data[$i]['jr_internal'])?> + + data[$i]['qp_supplier'],h($this->data[$i]['name'].' '.$this->data[$i]['first_name']))?> + + data[$i]['jr_comment'])?> + + data[$i]['novat'])?> + + data[$i]['vat'],$this->data[$i]['tva_sided']))?> + + data[$i]['tvac'])?> + + + db->execute('reconcile_date',array($this->data[$i]['jr_id'])); + $max=Database::num_row($ret_reconcile); + if ($max > 0) { + $sep=""; + for ($e=0;$e<$max;$e++) { + $row=Database::fetch_array($ret_reconcile, $e); + echo $sep.HtmlInput::detail_op($row['jr_id'],$row['jr_date'].' '. $row['jr_internal']); + $sep=' ,'; + } + } ?> +
+db->execute("detail_purchase",array($this->data[$i]['jr_internal'])); +$a_detail=Database::fetch_all($det); +?> + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
\ No newline at end of file diff --git a/include/template/acc_ledger_history_purchase_oneline.php b/include/template/acc_ledger_history_purchase_oneline.php new file mode 100644 index 000000000..3a6d78320 --- /dev/null +++ b/include/template/acc_ledger_history_purchase_oneline.php @@ -0,0 +1,152 @@ + + +if (!defined('ALLOWED')) + die('Appel direct ne sont pas permis'); + +/** + * @file + * @brief display purchase on one line with sum of VAT, Operation, Private exp. + * @todo prévoir aussi pour les non assujetti : faire disparaître les montants TVA + */ + +?> + + + + + + + + + + + + + + +data); +$tot_amount_novat=0; +$tot_amount_vat=0; +$tot_amount_tvac=0; +$tot_amount_private=0; +$tot_nonded_vat=0; +$tot_nonded_amount=0; + +for ($i=0;$i<$nb_data;$i++): + $odd=($i%2==0)?' class="even" ':' class="odd" '; + $tot_amount_novat=bcadd($tot_amount_novat,$this->data[$i]['novat']); + $tot_amount_vat=bcadd($tot_amount_vat,$this->data[$i]['vat']); + $tot_amount_vat=bcsub($tot_amount_vat,$this->data[$i]['tva_sided']); + $tot_amount_tvac=bcadd($tot_amount_tvac,$this->data[$i]['tvac']); + $tot_nonded_amount=bcadd($tot_nonded_amount,$this->data[$i]['noded_amount']); + $tot_nonded_amount=bcadd($tot_nonded_amount,$this->data[$i]['private_amount']); + $tot_nonded_vat=bcadd($tot_nonded_vat, $this->data[$i]['noded_vat']); +?> + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ data[$i]['jr_date']?> + + data[$i]['jr_date_paid']?> + + data[$i]['jr_pj_number']?> + + data[$i]['jr_id'], $this->data[$i]['jr_internal'])?> + + data[$i]['qp_supplier'],h($this->data[$i]['name'].' '.$this->data[$i]['first_name']." [ {$this->data[$i]['qcode']} ]"))?> + + data[$i]['jr_comment'])?> + + data[$i]['novat'])?> + + data[$i]['noded_amount'],$this->data[$i]['private_amount']));?> + + data[$i]['vat'],$this->data[$i]['tva_sided']))?> + + data[$i]['tvac'])?> + + + db->execute('reconcile_date',array($this->data[$i]['jr_id'])); + $max=Database::num_row($ret_reconcile); + if ($max > 0) { + $sep=""; + for ($e=0;$e<$max;$e++) { + $row=Database::fetch_array($ret_reconcile, $e); + echo $sep.HtmlInput::detail_op($row['jr_id'],$row['jr_date'].' '. $row['jr_internal']); + $sep=' ,'; + } + } ?> +
+ +
\ No newline at end of file diff --git a/include/template/acc_ledger_history_sale_detail.php b/include/template/acc_ledger_history_sale_detail.php index cfa9bf2a1..a48516380 100644 --- a/include/template/acc_ledger_history_sale_detail.php +++ b/include/template/acc_ledger_history_sale_detail.php @@ -83,7 +83,7 @@ foreach ($this->data as $line) { // Internal with detail echo "" . HtmlInput::detail_op($line['jr_id'], $line['jr_internal']) . ""; - // find the tiers (normally in $Row ! + // find the tiers (normally in $this->data ! $tiers =HtmlInput::history_card($line['qs_client'],h($line['name'].' '.$line['first_name'])."[{$line['qcode']}]"); echo td($tiers); diff --git a/include/template/acc_ledger_history_sale_extended.php b/include/template/acc_ledger_history_sale_extended.php index fdaa47206..effaf4365 100644 --- a/include/template/acc_ledger_history_sale_extended.php +++ b/include/template/acc_ledger_history_sale_extended.php @@ -78,7 +78,7 @@ for ($i=0;$i<$nb_data;$i++): data[$i]['jr_pj_number']?> - data[$i]['jr_internal']?> + data[$i]['jr_id'], $this->data[$i]['jr_internal'])?> data[$i]['qs_client'],h($this->data[$i]['name'].' '.$this->data[$i]['first_name']))?> @@ -111,7 +111,9 @@ for ($i=0;$i<$nb_data;$i++): - + + + db->execute("detail_sale",array($this->data[$i]['jr_internal'])); diff --git a/include/template/acc_history_ledger_sale_oneline.php b/include/template/acc_ledger_history_sale_oneline.php similarity index 97% rename from include/template/acc_history_ledger_sale_oneline.php rename to include/template/acc_ledger_history_sale_oneline.php index f3cfa48f8..45e1294b5 100644 --- a/include/template/acc_history_ledger_sale_oneline.php +++ b/include/template/acc_ledger_history_sale_oneline.php @@ -79,7 +79,7 @@ for ($i=0;$i<$nb_data;$i++): data[$i]['jr_pj_number']?> - data[$i]['jr_internal']?> + data[$i]['jr_id'], $this->data[$i]['jr_internal'])?> data[$i]['qs_client'],h($this->data[$i]['name'].' '.$this->data[$i]['first_name']." [ {$this->data[$i]['qcode']} ]"))?> diff --git a/scenario/acc_ledger_historyTest.php b/scenario/acc_ledger_historyTest.php index b0863baf2..361fef4cc 100644 --- a/scenario/acc_ledger_historyTest.php +++ b/scenario/acc_ledger_historyTest.php @@ -34,18 +34,17 @@ $cn=Dossier::connect(); $ledger_history=Acc_Ledger_History::factory($cn, $ledger, 216, 217, "E"); echo h1("Detailled Accounting"); -echo h2(_("export detail html all ledgers result = Detailled Accounting")); +echo h2(_("export detail html all ledgers result = Detailled Accounting from Acc_Ledger_History_Generic")); $ledger_history->export_detail_html(); -echo h2(_("Set mode to D etailled all_ledgers result = Detailled Accounting" )); +echo h2(_("Set mode to D etailled all_ledgers result = Detailled Accounting from Acc_Ledger_History_Generic" )); $ledger_history->set_m_mode("D"); $ledger_history->export_html(); -echo h2(_("Only VEN")); +echo h1(_("Only VEN from Acc_Ledger_History_Sale")); $ledger_history=Acc_Ledger_History::factory($cn, [2], 216, 217, "L"); $ledger_history->export_detail_html(); -echo h1("One line"); echo h2(_("Only VEN one line")); $ledger_history->set_a_ledger([2]); $ledger_history->set_m_mode("L"); @@ -66,3 +65,16 @@ $ledger_history=Acc_Ledger_History::factory($cn, [3,2], 216, 217, "L"); $ledger_history->export_oneline_html(); +echo h1("ACH from Acc_Ledger_History_Purchase"); +echo h2("Detailled accouting"); +$ledger_history=new Acc_Ledger_History_Purchase($cn,[3],216,217,"A"); +$ledger_history->export_html(); +echo h2("Ach one line"); +$ledger_history->set_m_mode("L"); +$ledger_history->export_html(); +echo h2("Ach Detail"); +$ledger_history->set_m_mode("D"); +$ledger_history->export_html(); +echo h2("Ach Extended"); +$ledger_history->set_m_mode("E"); +$ledger_history->export_html();