From 88085bdaf9287853426d6d19478438d16fd251b6 Mon Sep 17 00:00:00 2001 From: Lillem4n Date: Thu, 14 Mar 2013 18:57:59 +0100 Subject: [PATCH] VAT additions and some other stuff --- classes/controller/admin/bills.php | 17 +++++++++++------ classes/model/bill.php | 21 +++++++++++---------- classes/model/bills.php | 4 ++-- css/pdfs.css | 7 ++++++- xsl/admin/bills.xsl | 17 ++++++++--------- xsl/bill.xsl | 21 ++++++++++++++------- 6 files changed, 52 insertions(+), 35 deletions(-) diff --git a/classes/controller/admin/bills.php b/classes/controller/admin/bills.php index 80e7f0e..49e97a4 100644 --- a/classes/controller/admin/bills.php +++ b/classes/controller/admin/bills.php @@ -50,7 +50,6 @@ public function action_bill() $post->filter('trim'); $post_array = $post->as_array(); - if (isset($post_array['add_item'])) { $_SESSION['bills']['items'][(count($_SESSION['bills']['items']) + 1).'item'] = count($_SESSION['bills']['items']) + 1; @@ -63,19 +62,26 @@ public function action_bill() $vat_sum = 0; foreach ($_SESSION['bills']['items'] as $item_nr) { + $qty = (float)$post->get('qty_item_'.$item_nr); + if ($qty == 0) $qty = 1; + + $vat = (float)$post->get('vat_item_'.$item_nr); + if ($vat == 0) $vat = 1.25; + $item = array( 'artnr' => $post->get('artnr_item_'.$item_nr), 'spec' => $post->get('spec_item_'.$item_nr), 'price' => (float)$post->get('price_item_'.$item_nr), - 'qty' => (float)$post->get('qty_item_'.$item_nr), + 'vat' => $vat, + 'qty' => $qty, 'delivery_date' => date('Y-m-d', time()), ); if ($item != array('artnr'=>'','spec'=>'','price'=>0,'qty'=>0,'delivery_date'=>date('Y-m-d',time()))) { $items[] = $item; - $sum += ($item['qty'] * $item['price'] * 1.25); - $vat_sum += ($item['qty'] * $item['price'] * 0.25); + $sum += ($item['qty'] * $item['price'] * $item['vat']); + $vat_sum += ($item['qty'] * $item['price'] * ($item['vat'] - 1)); } } @@ -133,5 +139,4 @@ public function action_mark_as_paid() $this->redirect(); } - -} +} \ No newline at end of file diff --git a/classes/model/bill.php b/classes/model/bill.php index 96810a3..65866e2 100644 --- a/classes/model/bill.php +++ b/classes/model/bill.php @@ -33,15 +33,15 @@ public function get($detail = FALSE) * @param num $due_date (UNIX timestamp) * @param str $contact - Their reference * @param arr $items - array( - array( - 'artnr' => '239D', - 'spec' => 'What to bill for', - 'price' => 700, - 'qty' => 2, - 'delivery_date' => '2011-01-01' - ), - etc - ) + * array( + * 'artnr' => '239D', + * 'spec' => 'What to bill for', + * 'price' => 700, + * 'qty' => 2, + * 'delivery_date' => '2011-01-01' + * ), + * etc + * ) * @param str $comment - Optional */ public static function new_bill($customer_id, $due_date, $contact, $items, $comment = '') @@ -51,7 +51,7 @@ public static function new_bill($customer_id, $due_date, $contact, $items, $comm if (self::$prepared_insert == NULL) { self::$prepared_insert = $pdo->prepare('INSERT INTO bills (due_date,customer_id,customer_name,customer_orgnr,customer_contact,customer_tel,customer_email,customer_street,customer_zip,customer_city,comment,contact) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)'); - self::$prepared_item_insert = $pdo->prepare('INSERT INTO bills_items (item_id,bill_id,artnr,spec,qty,price,delivery_date) VALUES(?,?,?,?,?,?,?)'); + self::$prepared_item_insert = $pdo->prepare('INSERT INTO bills_items (item_id,bill_id,artnr,spec,qty,price,vat,delivery_date) VALUES(?,?,?,?,?,?,?,?)'); } $customer_model = new Customer($customer_id); @@ -82,6 +82,7 @@ public static function new_bill($customer_id, $due_date, $contact, $items, $comm $item['spec'], $item['qty'], $item['price'], + $item['vat'], date('Y-m-d', time()), )); } diff --git a/classes/model/bills.php b/classes/model/bills.php index 9bc08c6..5caf2e6 100644 --- a/classes/model/bills.php +++ b/classes/model/bills.php @@ -10,8 +10,8 @@ public static function get() return $pdo->query(' SELECT *, - (SELECT SUM(qty * price * 1.25) FROM bills_items WHERE bills_items.bill_id = bills.id) AS sum, - (SELECT SUM(qty * price * 0.25) FROM bills_items WHERE bills_items.bill_id = bills.id) AS vat + (SELECT SUM(qty * price * vat) FROM bills_items WHERE bills_items.bill_id = bills.id) AS sum, + (SELECT SUM(qty * price * (vat - 1)) FROM bills_items WHERE bills_items.bill_id = bills.id) AS vat FROM bills order by ID ASC; ')->fetchAll(PDO::FETCH_ASSOC); } diff --git a/css/pdfs.css b/css/pdfs.css index 2cbc626..2ad5691 100644 --- a/css/pdfs.css +++ b/css/pdfs.css @@ -245,7 +245,7 @@ table.items { border-left: 1px solid #a2a2a2; border-top-left-radius: 5px; - width: 98px; + width: 48px; } table.items th.spec @@ -258,6 +258,11 @@ table.items width: 83px; } + table.items th.vat + { + width: 50px; + } + table.items th.single_price { width: 82px; diff --git a/xsl/admin/bills.xsl b/xsl/admin/bills.xsl index 64ce995..0b11f4e 100644 --- a/xsl/admin/bills.xsl +++ b/xsl/admin/bills.xsl @@ -24,7 +24,6 @@ - @@ -53,6 +52,7 @@ Email sent Sum PDF + HTTP Action @@ -72,7 +72,8 @@ SEK - Link + Link + Link [Send email] @@ -107,20 +108,20 @@ - + - + - + - - + +

Items:

@@ -145,8 +146,6 @@ - -

---

diff --git a/xsl/bill.xsl b/xsl/bill.xsl index f06d644..0aa9603 100644 --- a/xsl/bill.xsl +++ b/xsl/bill.xsl @@ -4,8 +4,8 @@ @@ -111,6 +111,7 @@ Antal Á Pris Pris + Moms @@ -148,6 +149,12 @@
+ + + vat last + + + @@ -159,7 +166,7 @@ - Moms (25%) + Moms @@ -266,13 +273,13 @@ - + - +
@@ -286,13 +293,13 @@ - + - +