Skip to content

Commit

Permalink
VAT additions and some other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lillem4n committed Mar 14, 2013
1 parent ffc6696 commit 88085bd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 35 deletions.
17 changes: 11 additions & 6 deletions classes/controller/admin/bills.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -133,5 +139,4 @@ public function action_mark_as_paid()
$this->redirect();
}


}
}
21 changes: 11 additions & 10 deletions classes/model/bill.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '')
Expand All @@ -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);
Expand Down Expand Up @@ -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()),
));
}
Expand Down
4 changes: 2 additions & 2 deletions classes/model/bills.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 6 additions & 1 deletion css/pdfs.css
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ table.items
{
border-left: 1px solid #a2a2a2;
border-top-left-radius: 5px;
width: 98px;
width: 48px;
}

table.items th.spec
Expand All @@ -258,6 +258,11 @@ table.items
width: 83px;
}

table.items th.vat
{
width: 50px;
}

table.items th.single_price
{
width: 82px;
Expand Down
17 changes: 8 additions & 9 deletions xsl/admin/bills.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
</ul>
</xsl:template>


<xsl:template match="/">
<xsl:if test="/root/content[../meta/controller = 'bills' and ../meta/action = 'index']">
<xsl:call-template name="template">
Expand Down Expand Up @@ -53,6 +52,7 @@
<th>Email sent</th>
<th class="right">Sum</th>
<th>PDF</th>
<th>HTTP</th>
<th class="medium_row">Action</th>
</tr>
</thead>
Expand All @@ -72,7 +72,8 @@
<xsl:value-of select="format-number(number(sum), '###,###,###.00')" />
<xsl:text> SEK</xsl:text>
</td>
<td><a href="http://{/root/meta/domain}{/root/meta/base}{concat('user_content/pdf/bill_',@id,'.pdf')}">Link</a></td>
<td><a href="http://{/root/meta/domain}{/root/meta/base}user_content/pdf/bill_{@id}.pdf">Link</a></td>
<td><a href="http://{/root/meta/domain}{/root/meta/base}bill?billnr={@id}">Link</a></td>
<td>
<!--xsl:text>[</xsl:text><a href="http://{/root/meta/domain}{/root/meta/base}bill?billnr={@id}">Details</a><xsl:text>]</xsl:text-->
<xsl:text>[</xsl:text><a href="bills/email/{@id}">Send email</a><xsl:text>]</xsl:text>
Expand Down Expand Up @@ -107,20 +108,20 @@
</label>

<xsl:call-template name="form_line">
<xsl:with-param name="id" select="'due_date'" />
<xsl:with-param name="id" select="'due_date'" />
<xsl:with-param name="label" select="'Due date:'" />
</xsl:call-template>

<xsl:call-template name="form_line">
<xsl:with-param name="id" select="'contact'" />
<xsl:with-param name="id" select="'contact'" />
<xsl:with-param name="label" select="'Their reference:'" />
</xsl:call-template>

<xsl:call-template name="form_line">
<xsl:with-param name="id" select="'comment'" />
<xsl:with-param name="id" select="'comment'" />
<xsl:with-param name="label" select="'Comment:'" />
<xsl:with-param name="type" select="'textarea'" />
<xsl:with-param name="rows" select="'5'" />
<xsl:with-param name="type" select="'textarea'" />
<xsl:with-param name="rows" select="'5'" />
</xsl:call-template>

<h2>Items:</h2>
Expand All @@ -145,8 +146,6 @@
<xsl:call-template name="form_line">
<xsl:with-param name="id" select="concat('qty_item_',.)" />
<xsl:with-param name="label" select="'Quantity:'" />
<xsl:with-param name="value" select="'1'" />

</xsl:call-template>

<p>---</p>
Expand Down
21 changes: 14 additions & 7 deletions xsl/bill.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<xsl:output method="html" encoding="utf-8" />

<xsl:decimal-format
decimal-separator=','
grouping-separator='&#160;'
decimal-separator=','
grouping-separator='&#160;'
/>

<xsl:template match="/">
Expand Down Expand Up @@ -111,6 +111,7 @@
<th class="qty">Antal</th>
<th class="single_price">Á Pris</th>
<th class="price">Pris</th>
<th class="vat">Moms</th>
</tr>

<xsl:for-each select="/root/content/bill/items/item">
Expand Down Expand Up @@ -148,6 +149,12 @@
</xsl:if>
<xsl:value-of select="format-number(number(qty) * number(price), '#&#160;###,00')" />
</td>
<td class="price">
<xsl:if test="position() = count(/root/content/bill/items/item)">
<xsl:attribute name="class">vat last</xsl:attribute>
</xsl:if>
<xsl:value-of select="format-number(number(qty) * number(price) * (number(vat) - 1), '#&#160;###,00')" />
</td>
</tr>
</xsl:for-each>

Expand All @@ -159,7 +166,7 @@
</td>
</tr>
<tr class="bottom">
<td colspan="2" class="vat">Moms (25%)</td>
<td colspan="2" class="vat">Moms</td>
<td class="vat_value">
<xsl:call-template name="vat" />
</td>
Expand Down Expand Up @@ -266,13 +273,13 @@

<xsl:call-template name="vat">
<xsl:with-param name="position" select="$position + 1" />
<xsl:with-param name="sum" select="$sum + number(/root/content/bill/items/item[$position]/qty) * number(/root/content/bill/items/item[$position]/price)"/>
<xsl:with-param name="sum" select="$sum + number(/root/content/bill/items/item[$position]/qty) * number(/root/content/bill/items/item[$position]/price) * (number(/root/content/bill/items/item[$position]/vat) - 1)"/>
</xsl:call-template>

</xsl:when>

<xsl:otherwise>
<xsl:value-of select="format-number($sum * 0.25, '#&#160;###,00')" />
<xsl:value-of select="format-number($sum, '#&#160;###,00')" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Expand All @@ -286,13 +293,13 @@

<xsl:call-template name="tot">
<xsl:with-param name="position" select="$position + 1" />
<xsl:with-param name="sum" select="$sum + number(/root/content/bill/items/item[$position]/qty) * number(/root/content/bill/items/item[$position]/price)"/>
<xsl:with-param name="sum" select="$sum + number(/root/content/bill/items/item[$position]/qty) * number(/root/content/bill/items/item[$position]/price) * number(/root/content/bill/items/item[$position]/vat)"/>
</xsl:call-template>

</xsl:when>

<xsl:otherwise>
<xsl:value-of select="format-number($sum * 1.25, '#&#160;###,00')" />
<xsl:value-of select="format-number($sum, '#&#160;###,00')" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Expand Down

0 comments on commit 88085bd

Please sign in to comment.