db-update.txt | 54 system/application/assets/css/custom.css | 6 system/application/assets/css/tables.css | 27 system/application/controllers/admin/create.php | 2 system/application/controllers/admin/schema.sql | 47 system/application/controllers/inventory/account.php | 24 system/application/controllers/inventory/stockgroup.php | 302 + system/application/controllers/inventory/stockitem.php | 434 ++ system/application/controllers/inventory/stocktransfer.php | 1175 +++++++ system/application/controllers/inventory/stockunit.php | 292 + system/application/controllers/inventory/stockvoucher.php | 1550 ++++++++++ system/application/controllers/inventory/welcome.php | 18 system/application/controllers/ledger.php | 96 system/application/controllers/setting/cf.php | 2 system/application/controllers/setting/vouchertypes.php | 35 system/application/controllers/voucher.php | 61 system/application/controllers/welcome.php | 39 system/application/helpers/MY_form_helper.php | 44 system/application/helpers/access_helper.php | 57 system/application/helpers/custom_helper.php | 10 system/application/libraries/Accountlist.php | 4 system/application/libraries/General.php | 5 system/application/libraries/MY_Form_validation.php | 36 system/application/libraries/Startup.php | 2 system/application/libraries/Stockstree.php | 139 system/application/models/ledger_model.php | 86 system/application/models/stock_group_model.php | 37 system/application/models/stock_item_model.php | 116 system/application/models/stock_unit_model.php | 21 system/application/views/admin/create.php | 8 system/application/views/group/add.php | 2 system/application/views/group/edit.php | 2 system/application/views/inventory/account/index.php | 28 system/application/views/inventory/stockgroup/add.php | 22 system/application/views/inventory/stockgroup/edit.php | 22 system/application/views/inventory/stockitem/add.php | 97 system/application/views/inventory/stockitem/edit.php | 97 system/application/views/inventory/stocktransfer/add.php | 401 ++ system/application/views/inventory/stocktransfer/downloadpreview.php | 125 system/application/views/inventory/stocktransfer/edit.php | 401 ++ system/application/views/inventory/stocktransfer/email.php | 54 system/application/views/inventory/stocktransfer/emailpreview.php | 70 system/application/views/inventory/stocktransfer/printpreview.php | 74 system/application/views/inventory/stocktransfer/view.php | 71 system/application/views/inventory/stockunit/add.php | 31 system/application/views/inventory/stockunit/edit.php | 31 system/application/views/inventory/stockvoucher/add.php | 473 +++ system/application/views/inventory/stockvoucher/downloadpreview.php | 166 + system/application/views/inventory/stockvoucher/edit.php | 473 +++ system/application/views/inventory/stockvoucher/email.php | 54 system/application/views/inventory/stockvoucher/emailpreview.php | 107 system/application/views/inventory/stockvoucher/printpreview.php | 115 system/application/views/inventory/stockvoucher/view.php | 119 system/application/views/ledger/add.php | 36 system/application/views/ledger/edit.php | 35 system/application/views/report/balancesheet.php | 4 system/application/views/report/trialbalance.php | 2 system/application/views/setting/vouchertypes/add.php | 43 system/application/views/setting/vouchertypes/edit.php | 23 system/application/views/template.php | 3 system/application/views/voucher/add.php | 2 system/application/views/voucher/downloadpreview.php | 2 system/application/views/voucher/edit.php | 2 system/application/views/voucher/emailpreview.php | 2 system/application/views/voucher/index.php | 38 system/application/views/voucher/printpreview.php | 2 system/application/views/voucher/view.php | 6 system/application/views/welcome.php | 2 68 files changed, 7863 insertions(+), 103 deletions(-)
New commits: commit bea2661db18740953573897de86ef46ece13893f Author: Prashant P Shah pshah.mumbai@gmail.com Date: Wed Mar 16 19:35:41 2011 +0530
Changed A/C to Account
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/libraries/Accountlist.php b/system/application/libraries/Accountlist.php index bd53cec..b7b2acf 100644 --- a/system/application/libraries/Accountlist.php +++ b/system/application/libraries/Accountlist.php @@ -124,7 +124,7 @@ class Accountlist else echo " " . $this->name; echo "</td>"; - echo "<td>Group A/C</td>"; + echo "<td>Group</td>"; echo "<td>-</td>"; echo "<td>-</td>";
@@ -153,7 +153,7 @@ class Accountlist echo $this->print_space($this->counter); echo " " . anchor('report/ledgerst/' . $data['id'], $data['name'], array('title' => $data['name'] . ' Ledger Statement', 'style' => 'color:#000000')); echo "</td>"; - echo "<td>Ledger A/C</td>"; + echo "<td>Ledger</td>"; echo "<td>" . convert_opening($data['opbalance'], $data['optype']) . "</td>"; echo "<td>" . convert_amount_dc($data['total']) . "</td>"; echo "<td class="td-actions">" . anchor('ledger/edit/' . $data['id'], 'Edit', array('title' => "Edit Ledger", 'class' => 'red-link')); diff --git a/system/application/views/group/add.php b/system/application/views/group/add.php index e6a91b9..c6584dc 100644 --- a/system/application/views/group/add.php +++ b/system/application/views/group/add.php @@ -30,7 +30,7 @@ $(document).ready(function() { echo "<span id="tooltip-target-1">"; echo form_checkbox('affects_gross', 1, $affects_gross) . " Affects Gross Profit/Loss Calculations"; echo "</span>"; - echo "<span id="tooltip-content-1">If selected the Group A/C will affect Gross Profit and Loss calculations, otherwise it will affect only Net Profit and Loss calculations.</span>"; + echo "<span id="tooltip-content-1">If selected the Group Account will affect Gross Profit and Loss calculations, otherwise it will affect only Net Profit and Loss calculations.</span>"; echo "</p>";
echo "<p>"; diff --git a/system/application/views/group/edit.php b/system/application/views/group/edit.php index a5aac01..6b88c85 100644 --- a/system/application/views/group/edit.php +++ b/system/application/views/group/edit.php @@ -30,7 +30,7 @@ $(document).ready(function() { echo "<span id="tooltip-target-1">"; echo form_checkbox('affects_gross', 1, $affects_gross) . " Affects Gross Profit/Loss Calculations"; echo "</span>"; - echo "<span id="tooltip-content-1">If selected the Group A/C will affect Gross Profit and Loss calculations, otherwise it will affect only Net Profit and Loss calculations.</span>"; + echo "<span id="tooltip-content-1">If selected the Group Account will affect Gross Profit and Loss calculations, otherwise it will affect only Net Profit and Loss calculations.</span>"; echo "</p>";
echo "<p>"; diff --git a/system/application/views/inventory/stockvoucher/add.php b/system/application/views/inventory/stockvoucher/add.php index bd77279..0926e66 100644 --- a/system/application/views/inventory/stockvoucher/add.php +++ b/system/application/views/inventory/stockvoucher/add.php @@ -310,7 +310,7 @@ $(document).ready(function() { echo "<table border=0 cellpadding=2>"; echo "<tr>"; echo "<td align="right">"; - echo form_label('Purchase Ledger A/C', 'main_account'); + echo form_label('Purchase Ledger', 'main_account'); echo "</td>"; echo "<td>"; echo form_input_ledger('main_account', $main_account_active, '', $type = 'purchase'); @@ -332,7 +332,7 @@ $(document).ready(function() { echo "<table border=0 cellpadding=2>"; echo "<tr>"; echo "<td align="right">"; - echo form_label('Sales Ledger A/C', 'main_account'); + echo form_label('Sales Ledger', 'main_account'); echo "</td>"; echo "<td>"; echo form_input_ledger('main_account', $main_account_active, '', $type = 'sale'); @@ -411,7 +411,7 @@ $(document).ready(function() { echo "<br />";
echo "<table class="voucher-table">"; - echo "<thead><tr><th>Type</th><th>Ledger A/C</th><th>Rate %</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + echo "<thead><tr><th>Type</th><th>Ledger Account</th><th>Rate %</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>";
foreach ($ledger_dc as $i => $ledger) { diff --git a/system/application/views/inventory/stockvoucher/downloadpreview.php b/system/application/views/inventory/stockvoucher/downloadpreview.php index 31987c0..2ce3e19 100644 --- a/system/application/views/inventory/stockvoucher/downloadpreview.php +++ b/system/application/views/inventory/stockvoucher/downloadpreview.php @@ -74,9 +74,9 @@ <td align="right"> <?php if ($current_voucher_type['stock_voucher_type'] == '1') - echo "Purchase Ledger A/C :"; + echo "Purchase Ledger :"; else - echo "Sale Ledger A/C :"; + echo "Sale Ledger :"; ?> </td> <td class="last-item"> @@ -130,7 +130,7 @@
<table class="print-voucher-table"> <thead> - <tr class="tr-title"><th>Ledger A/C</th>><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr> + <tr class="tr-title"><th>Ledger Account</th>><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr> </thead> <tbody> <?php diff --git a/system/application/views/inventory/stockvoucher/edit.php b/system/application/views/inventory/stockvoucher/edit.php index d58d6c3..3650f5c 100644 --- a/system/application/views/inventory/stockvoucher/edit.php +++ b/system/application/views/inventory/stockvoucher/edit.php @@ -310,7 +310,7 @@ $(document).ready(function() { echo "<table border=0 cellpadding=2>"; echo "<tr>"; echo "<td align="right">"; - echo form_label('Purchase Ledger A/C', 'main_account'); + echo form_label('Purchase Ledger', 'main_account'); echo "</td>"; echo "<td>"; echo form_input_ledger('main_account', $main_account_active, '', $type = 'purchase'); @@ -332,7 +332,7 @@ $(document).ready(function() { echo "<table border=0 cellpadding=2>"; echo "<tr>"; echo "<td align="right">"; - echo form_label('Sales Ledger A/C', 'main_account'); + echo form_label('Sales Ledger', 'main_account'); echo "</td>"; echo "<td>"; echo form_input_ledger('main_account', $main_account_active, '', $type = 'sale'); @@ -411,7 +411,7 @@ $(document).ready(function() { echo "<br />";
echo "<table class="voucher-table">"; - echo "<thead><tr><th>Type</th><th>Ledger A/C</th><th>Rate %</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + echo "<thead><tr><th>Type</th><th>Ledger Account</th><th>Rate %</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>";
foreach ($ledger_dc as $i => $ledger) { diff --git a/system/application/views/inventory/stockvoucher/emailpreview.php b/system/application/views/inventory/stockvoucher/emailpreview.php index e256c94..3424536 100644 --- a/system/application/views/inventory/stockvoucher/emailpreview.php +++ b/system/application/views/inventory/stockvoucher/emailpreview.php @@ -15,9 +15,9 @@ <td align="right"> <?php if ($current_voucher_type['stock_voucher_type'] == '1') - echo "Purchase Ledger A/C :"; + echo "Purchase Ledger :"; else - echo "Sale Ledger A/C :"; + echo "Sale Ledger :"; ?> </td> <td> @@ -71,7 +71,7 @@
<table border=1 cellpadding=6> <thead> - <tr><th align="left">Ledger A/C</th><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr> + <tr><th align="left">Ledger Account</th><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr> </thead> <tbody> <?php diff --git a/system/application/views/inventory/stockvoucher/printpreview.php b/system/application/views/inventory/stockvoucher/printpreview.php index cdb545d..0d30975 100644 --- a/system/application/views/inventory/stockvoucher/printpreview.php +++ b/system/application/views/inventory/stockvoucher/printpreview.php @@ -20,9 +20,9 @@ <td align=\"right\"> <?php if ($current_voucher_type['stock_voucher_type'] == '1') - echo "Purchase Ledger A/C"; + echo "Purchase Ledger"; else - echo "Sale Ledger A/C"; + echo "Sale Ledger"; ?> </td> <td> @@ -76,7 +76,7 @@
<table id="print-voucher-table"> <thead> - <tr class="tr-title"><th>Ledger A/C</th><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr> + <tr class="tr-title"><th>Ledger Account</th><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr> </thead> <tbody> <?php diff --git a/system/application/views/inventory/stockvoucher/view.php b/system/application/views/inventory/stockvoucher/view.php index b46092d..665a06e 100644 --- a/system/application/views/inventory/stockvoucher/view.php +++ b/system/application/views/inventory/stockvoucher/view.php @@ -8,9 +8,9 @@ Voucher Date : <span class="bold"><?php echo date_mysql_to_php_display($cur_vouc <td align=\"right\"> <?php if ($current_voucher_type['stock_voucher_type'] == '1') - echo "Purchase Ledger A/C :"; + echo "Purchase Ledger :"; else - echo "Sale Ledger A/C :"; + echo "Sale Ledger :"; ?> </td> <td> @@ -60,7 +60,7 @@ foreach ($cur_voucher_stock_items->result() as $row) <br />
<table border=0 cellpadding=5 class="simple-table voucher-view-table"> -<thead><tr><th>Type</th><th>Ledger A/C</th><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr></thead> +<thead><tr><th>Type</th><th>Ledger Account</th><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr></thead> <?php foreach ($cur_voucher_ledgers->result() as $row) { diff --git a/system/application/views/ledger/add.php b/system/application/views/ledger/add.php index bd1fa38..be7d10b 100644 --- a/system/application/views/ledger/add.php +++ b/system/application/views/ledger/add.php @@ -55,7 +55,7 @@ $(document).ready(function() { echo "<span id="tooltip-target-2">"; echo form_checkbox('ledger_type_cashbank', 1, $ledger_type_cashbank, 'id="ledger_type_cashbank"') . " Bank or Cash Account"; echo "</span>"; - echo "<span id="tooltip-content-2">Select if Ledger A/C is a Bank A/C or a Cash A/C.</span>"; + echo "<span id="tooltip-content-2">Select if Ledger Account is of type Bank or Cash Account.</span>"; echo "</p>";
echo "<p>"; diff --git a/system/application/views/ledger/edit.php b/system/application/views/ledger/edit.php index abf2e49..8ad4cfd 100644 --- a/system/application/views/ledger/edit.php +++ b/system/application/views/ledger/edit.php @@ -54,7 +54,7 @@ $(document).ready(function() { echo "<span id="tooltip-target-2">"; echo form_checkbox('ledger_type_cashbank', 1, $ledger_type_cashbank, 'id="ledger_type_cashbank"') . " Bank or Cash Account"; echo "</span>"; - echo "<span id="tooltip-content-2">Select if Ledger A/C is a Bank A/C or a Cash A/C.</span>"; + echo "<span id="tooltip-content-2">Select if Ledger Account is of type Bank or Cash Account.</span>"; echo "</p>";
echo "<p>"; diff --git a/system/application/views/report/balancesheet.php b/system/application/views/report/balancesheet.php index a2fa868..ce19d41 100644 --- a/system/application/views/report/balancesheet.php +++ b/system/application/views/report/balancesheet.php @@ -57,7 +57,7 @@ { $total += $pandl; echo "<tr valign="top">"; - echo "<td class="bold">Profit & Loss A/C (Net Profit)</td>"; + echo "<td class="bold">Profit & Loss Account (Net Profit)</td>"; echo "<td align="right" class="bold">" . convert_cur($pandl) . "</td>"; echo "</tr>"; } else { @@ -116,7 +116,7 @@ } else { $total += -$pandl; echo "<tr valign="top">"; - echo "<td class="bold">Profit & Loss A/C (Net Loss)</td>"; + echo "<td class="bold">Profit & Loss Account (Net Loss)</td>"; echo "<td align="right" class="bold">" . convert_cur(-$pandl) . "</td>"; echo "</tr>"; } diff --git a/system/application/views/report/trialbalance.php b/system/application/views/report/trialbalance.php index 5fe7878..438096f 100644 --- a/system/application/views/report/trialbalance.php +++ b/system/application/views/report/trialbalance.php @@ -3,7 +3,7 @@ $temp_cr_total = 0;
echo "<table border=0 cellpadding=5 class="simple-table trial-balance-table">"; - echo "<thead><tr><th>Ledger A/C</th><th>O/P Balance</th><th>C/L Balance</th><th>Dr Total</th><th>Cr Total</th></tr></thead>"; + echo "<thead><tr><th>Ledger Account</th><th>O/P Balance</th><th>C/L Balance</th><th>Dr Total</th><th>Cr Total</th></tr></thead>"; $this->load->model('Ledger_model'); $all_ledgers = $this->Ledger_model->get_all_ledgers(); $odd_even = "odd"; diff --git a/system/application/views/voucher/add.php b/system/application/views/voucher/add.php index 06d2b97..8e9109a 100644 --- a/system/application/views/voucher/add.php +++ b/system/application/views/voucher/add.php @@ -213,7 +213,7 @@ $(document).ready(function() { echo "</p>";
echo "<table class="voucher-table">"; - echo "<thead><tr><th>Type</th><th>Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + echo "<thead><tr><th>Type</th><th>Ledger Account</th><th>Dr Amount</th><th>Cr Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>";
foreach ($ledger_dc as $i => $ledger) { diff --git a/system/application/views/voucher/downloadpreview.php b/system/application/views/voucher/downloadpreview.php index 61b3f52..7a8bd40 100644 --- a/system/application/views/voucher/downloadpreview.php +++ b/system/application/views/voucher/downloadpreview.php @@ -70,7 +70,7 @@ <br /> <table id="print-voucher-table"> <thead> - <tr class="tr-title"><th>Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr> + <tr class="tr-title"><th>Ledger Account</th><th>Dr Amount</th><th>Cr Amount</th></tr> </thead> <tbody> <?php diff --git a/system/application/views/voucher/edit.php b/system/application/views/voucher/edit.php index 3eb7b60..4bddf0f 100644 --- a/system/application/views/voucher/edit.php +++ b/system/application/views/voucher/edit.php @@ -210,7 +210,7 @@ $(document).ready(function() { echo "</p>";
echo "<table class="voucher-table">"; - echo "<thead><tr><th>Type</th><th>Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th><th colspan=2>Actions</th><th colspan=2>Cur Balance</th></tr></thead>"; + echo "<thead><tr><th>Type</th><th>Ledger Account</th><th>Dr Amount</th><th>Cr Amount</th><th colspan=2>Actions</th><th colspan=2>Cur Balance</th></tr></thead>";
foreach ($ledger_dc as $i => $ledger) { diff --git a/system/application/views/voucher/emailpreview.php b/system/application/views/voucher/emailpreview.php index 0b0febd..e694213 100644 --- a/system/application/views/voucher/emailpreview.php +++ b/system/application/views/voucher/emailpreview.php @@ -11,7 +11,7 @@ <p><?php echo $current_voucher_type['name']; ?> Voucher Date : <strong><?php echo $voucher_date; ?></strong></p> <table border=1 cellpadding=6> <thead> - <tr><th align="left">Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr> + <tr><th align="left">Ledger Account</th><th>Dr Amount</th><th>Cr Amount</th></tr> </thead> <tbody> <?php diff --git a/system/application/views/voucher/index.php b/system/application/views/voucher/index.php index 1e064c1..099d362 100644 --- a/system/application/views/voucher/index.php +++ b/system/application/views/voucher/index.php @@ -4,15 +4,7 @@
<table border=0 cellpadding=5 class="simple-table"> <thead> - <tr> - <th>Date</th> - <th>No</th> - <th>Ledger A/C</th> - <th>Type</th> - <th>DR Amount</th> - <th>CR Amount</th> - <th></th> - </tr> + <tr><th>Date</th><th>No.</th><th>Ledger Account</th><th>Type</th><th>DR Amount</th><th>CR Amount</th><th></th></tr> </thead> <tbody> <?php diff --git a/system/application/views/voucher/printpreview.php b/system/application/views/voucher/printpreview.php index 2d8f4a6..3c1a554 100644 --- a/system/application/views/voucher/printpreview.php +++ b/system/application/views/voucher/printpreview.php @@ -16,7 +16,7 @@ <br /> <table id="print-voucher-table"> <thead> - <tr class="tr-title"><th>Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr> + <tr class="tr-title"><th>Ledger Account</th><th>Dr Amount</th><th>Cr Amount</th></tr> </thead> <tbody> <?php diff --git a/system/application/views/voucher/view.php b/system/application/views/voucher/view.php index 15e3f7d..c7cd107 100644 --- a/system/application/views/voucher/view.php +++ b/system/application/views/voucher/view.php @@ -4,7 +4,7 @@ Voucher Date : <span class="bold"><?php echo date_mysql_to_php_display($cur_vouc </p>
<table border=0 cellpadding=5 class="simple-table voucher-view-table"> -<thead><tr><th>Type</th><th>Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr></thead> +<thead><tr><th>Type</th><th>Ledger Account</th><th>Dr Amount</th><th>Cr Amount</th></tr></thead> <?php $odd_even = "odd"; foreach ($cur_voucher_ledgers->result() as $row) diff --git a/system/application/views/welcome.php b/system/application/views/welcome.php index 6198805..0955ef5 100644 --- a/system/application/views/welcome.php +++ b/system/application/views/welcome.php @@ -103,7 +103,7 @@ jQuery(document).ready(function () { </div> <div class="clear"></div> <div id="dashboard-cash-bank" class="dashboard-item"> - <div class="dashboard-title">Bank and Cash A/C's</div> + <div class="dashboard-title">Bank and Cash Accounts</div> <div class="dashboard-content"> <?php if ($bank_cash_account)
commit ba46e68f4f1c2e2614c16dbabf838ad0b8bb4f60 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Mon Mar 14 22:32:02 2011 +0530
Updated stock transfer
- Show the rate of item value on first load - View stock transfer shows correct source and destination
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stocktransfer.php b/system/application/controllers/inventory/stocktransfer.php index bf462b9..458ad56 100644 --- a/system/application/controllers/inventory/stocktransfer.php +++ b/system/application/controllers/inventory/stocktransfer.php @@ -49,13 +49,13 @@ class StockTransfer extends Controller { }
/* Load current stock items details */ - $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 1)->order_by('id', 'asc'); + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 2)->order_by('id', 'asc'); $cur_voucher_source_stock_items = $this->db->get(); if ($cur_voucher_source_stock_items->num_rows() < 1) { $this->messages->add('Voucher has no associated source stock items.', 'error'); } - $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 2)->order_by('id', 'asc'); + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 1)->order_by('id', 'asc'); $cur_voucher_dest_stock_items = $this->db->get(); if ($cur_voucher_dest_stock_items->num_rows() < 1) { diff --git a/system/application/views/inventory/stocktransfer/add.php b/system/application/views/inventory/stocktransfer/add.php index cd31321..2c836f8 100644 --- a/system/application/views/inventory/stocktransfer/add.php +++ b/system/application/views/inventory/stocktransfer/add.php @@ -2,6 +2,8 @@
$(document).ready(function() {
+ var firstTime = true; + /************************ SOURCE STOCK ITEM ***************************/ /* Stock Item dropdown changed */ $('.stock-item-dropdown').live('change', function() { @@ -30,18 +32,20 @@ $(document).ready(function() { } });
- $.ajax({ - url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, - success: function(data) { - var sell_price = parseFloat(data); - if (isNaN(sell_price)) - sell_price = 0; - if (sell_price <= 0) - rowid.parent().next().next().children().val(""); - else - rowid.parent().next().next().children().val(sell_price); - } - }); + if (!firstTime) { + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, + success: function(data) { + var sell_price = parseFloat(data); + if (isNaN(sell_price)) + sell_price = 0; + if (sell_price <= 0) + rowid.parent().next().next().children().val(""); + else + rowid.parent().next().next().children().val(sell_price); + } + }); + } } else { rowid.parent().next().next().next().next().next().next().children().text(""); } @@ -155,18 +159,20 @@ $(document).ready(function() { } });
- $.ajax({ - url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, - success: function(data) { - var sell_price = parseFloat(data); - if (isNaN(sell_price)) - sell_price = 0; - if (sell_price <= 0) - rowid.parent().next().next().children().val(""); - else - rowid.parent().next().next().children().val(sell_price); - } - }); + if (!firstTime) { + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, + success: function(data) { + var sell_price = parseFloat(data); + if (isNaN(sell_price)) + sell_price = 0; + if (sell_price <= 0) + rowid.parent().next().next().children().val(""); + else + rowid.parent().next().next().children().val(sell_price); + } + }); + } } else { rowid.parent().next().next().next().next().next().next().children().text(""); } @@ -253,6 +259,7 @@ $(document).ready(function() { $('.stock-item-dropdown').trigger('change'); $('table td .dest-recalculate').trigger('click'); $('table td .source-recalculate').trigger('click'); + firstTime = false; });
</script> diff --git a/system/application/views/inventory/stocktransfer/edit.php b/system/application/views/inventory/stocktransfer/edit.php index 32586d4..ba7ee0c 100644 --- a/system/application/views/inventory/stocktransfer/edit.php +++ b/system/application/views/inventory/stocktransfer/edit.php @@ -2,6 +2,8 @@
$(document).ready(function() {
+ var firstTime = true; + /************************ SOURCE STOCK ITEM ***************************/ /* Stock Item dropdown changed */ $('.stock-item-dropdown').live('change', function() { @@ -30,18 +32,20 @@ $(document).ready(function() { } });
- $.ajax({ - url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, - success: function(data) { - var sell_price = parseFloat(data); - if (isNaN(sell_price)) - sell_price = 0; - if (sell_price <= 0) - rowid.parent().next().next().children().val(""); - else - rowid.parent().next().next().children().val(sell_price); - } - }); + if (!firstTime) { + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, + success: function(data) { + var sell_price = parseFloat(data); + if (isNaN(sell_price)) + sell_price = 0; + if (sell_price <= 0) + rowid.parent().next().next().children().val(""); + else + rowid.parent().next().next().children().val(sell_price); + } + }); + } } else { rowid.parent().next().next().next().next().next().next().children().text(""); } @@ -155,18 +159,20 @@ $(document).ready(function() { } });
- $.ajax({ - url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, - success: function(data) { - var sell_price = parseFloat(data); - if (isNaN(sell_price)) - sell_price = 0; - if (sell_price <= 0) - rowid.parent().next().next().children().val(""); - else - rowid.parent().next().next().children().val(sell_price); - } - }); + if (!firstTime) { + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, + success: function(data) { + var sell_price = parseFloat(data); + if (isNaN(sell_price)) + sell_price = 0; + if (sell_price <= 0) + rowid.parent().next().next().children().val(""); + else + rowid.parent().next().next().children().val(sell_price); + } + }); + } } else { rowid.parent().next().next().next().next().next().next().children().text(""); } @@ -253,6 +259,7 @@ $(document).ready(function() { $('.stock-item-dropdown').trigger('change'); $('table td .dest-recalculate').trigger('click'); $('table td .source-recalculate').trigger('click'); + firstTime = false; });
</script>
commit 236d7baf0609797ec86d1fb4f14a9f5882dad637 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sun Mar 13 22:33:52 2011 +0530
Added edit stock transfer
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stocktransfer.php b/system/application/controllers/inventory/stocktransfer.php index 6455c42..bf462b9 100644 --- a/system/application/controllers/inventory/stocktransfer.php +++ b/system/application/controllers/inventory/stocktransfer.php @@ -467,7 +467,7 @@ class StockTransfer extends Controller { return; }
- /* Form fields - Voucher */ + /* Form fields */ $data['voucher_number'] = array( 'name' => 'voucher_number', 'id' => 'voucher_number', @@ -489,70 +489,52 @@ class StockTransfer extends Controller { 'rows' => '4', 'value' => $cur_voucher->narration, ); + $data['voucher_id'] = $voucher_id; - $data['main_account_active'] = 0; - $data['main_entity_active'] = 0; $data['voucher_type_id'] = $voucher_type_id; $data['current_voucher_type'] = $current_voucher_type; $data['voucher_tag'] = $cur_voucher->tag_id; $data['voucher_tags'] = $this->Tag_model->get_all_tags(); - $data['has_reconciliation'] = FALSE;
/* Load current ledger details if not $_POST */ if ( ! $_POST) { - /* main - account */ - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1); - $cur_main_account_q = $this->db->get(); - $cur_main_account = $cur_main_account_q->row(); - $data['main_account_active'] = $cur_main_account->ledger_id; - - /* main - entity */ - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2); - $cur_main_entity_q = $this->db->get(); - $cur_main_entity = $cur_main_entity_q->row(); - $data['main_entity_active'] = $cur_main_entity->ledger_id; - - /* ledgers */ - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3); - $cur_ledgers_q = $this->db->get(); + /* source stock items */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 2); + $cur_stock_item_q = $this->db->get(); $counter = 0; - foreach ($cur_ledgers_q->result() as $row) + foreach ($cur_stock_item_q->result() as $row) { - $data['ledger_dc'][$counter] = $row->dc; - $data['ledger_id'][$counter] = $row->ledger_id; - $data['rate_item'][$counter] = $row->stock_rate; - $data['amount_item'][$counter] = $row->amount; - if ($row->reconciliation_date) - $data['has_reconciliation'] = TRUE; + $data['source_stock_item_id'][$counter] = $row->stock_item_id; + $data['source_stock_item_quantity'][$counter] = $row->quantity; + $data['source_stock_item_rate_per_unit'][$counter] = $row->rate_per_unit; + $data['source_stock_item_amount'][$counter] = $row->total; $counter++; } /* one extra rows */ - $data['ledger_dc'][$counter] = 'D'; - $data['ledger_id'][$counter] = 0; - $data['rate_item'][$counter] = ""; - $data['amount_item'][$counter] = ""; + $data['source_stock_item_id'][$counter] = '0'; + $data['source_stock_item_quantity'][$counter] = ""; + $data['source_stock_item_rate_per_unit'][$counter] = ""; + $data['source_stock_item_amount'][$counter] = ""; $counter++;
- /* stock items */ - $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id); + /* destination stock items */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 1); $cur_stock_item_q = $this->db->get(); $counter = 0; foreach ($cur_stock_item_q->result() as $row) { - $data['stock_item_id'][$counter] = $row->stock_item_id; - $data['stock_item_quantity'][$counter] = $row->quantity; - $data['stock_item_rate_per_unit'][$counter] = $row->rate_per_unit; - $data['stock_item_discount'][$counter] = $row->discount; - $data['stock_item_amount'][$counter] = $row->total; + $data['dest_stock_item_id'][$counter] = $row->stock_item_id; + $data['dest_stock_item_quantity'][$counter] = $row->quantity; + $data['dest_stock_item_rate_per_unit'][$counter] = $row->rate_per_unit; + $data['dest_stock_item_amount'][$counter] = $row->total; $counter++; } /* one extra rows */ - $data['stock_item_id'][$counter] = '0'; - $data['stock_item_quantity'][$counter] = ""; - $data['stock_item_rate_per_unit'][$counter] = ""; - $data['stock_item_discount'][$counter] = ""; - $data['stock_item_amount'][$counter] = ""; + $data['dest_stock_item_id'][$counter] = '0'; + $data['dest_stock_item_quantity'][$counter] = ""; + $data['dest_stock_item_rate_per_unit'][$counter] = ""; + $data['dest_stock_item_amount'][$counter] = ""; $counter++; }
@@ -562,31 +544,24 @@ class StockTransfer extends Controller { else $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|required|is_natural_no_zero|uniquevouchernowithid[' . $voucher_type_id . '.' . $voucher_id . ']'); $this->form_validation->set_rules('voucher_date', 'Voucher Date', 'trim|required|is_date|is_date_within_range'); - if ($current_voucher_type['stock_voucher_type'] == '1') - { - $this->form_validation->set_rules('main_account', 'Purchase Ledger A/C', 'trim|required'); - $this->form_validation->set_rules('main_entity', 'Creditors (Supplier)', 'trim|required'); - } else { - $this->form_validation->set_rules('main_account', 'Sale Ledger A/C', 'trim|required'); - $this->form_validation->set_rules('main_entity', 'Debtor (Customer)', 'trim|required'); - } + $this->form_validation->set_rules('voucher_narration', 'trim'); $this->form_validation->set_rules('voucher_tag', 'Tag', 'trim|is_natural');
/* Debit and Credit amount validation */ if ($_POST) { - foreach ($this->input->post('stock_item_id', TRUE) as $id => $stock_data) + foreach ($this->input->post('source_stock_item_id', TRUE) as $id => $stock_data) { - $this->form_validation->set_rules('stock_item_quantity[' . $id . ']', 'Stock Item Quantity', 'trim|quantity'); - $this->form_validation->set_rules('stock_item_rate_per_unit[' . $id . ']', 'Stock Item Rate Per Unit', 'trim|currency'); - $this->form_validation->set_rules('stock_item_discount[' . $id . ']', 'Stock Item Discount', 'trim|discount'); - $this->form_validation->set_rules('stock_item_amount[' . $id . ']', 'Stock Item Amount', 'trim|currency'); + $this->form_validation->set_rules('source_stock_item_quantity[' . $id . ']', 'Stock Item Quantity', 'trim|quantity'); + $this->form_validation->set_rules('source_stock_item_rate_per_unit[' . $id . ']', 'Stock Item Rate Per Unit', 'trim|currency'); + $this->form_validation->set_rules('source_stock_item_amount[' . $id . ']', 'Stock Item Amount', 'trim|currency'); } - foreach ($this->input->post('ledger_dc', TRUE) as $id => $ledger_data) + foreach ($this->input->post('dest_stock_item_id', TRUE) as $id => $stock_data) { - $this->form_validation->set_rules('rate_item[' . $id . ']', 'Rate %', 'trim|rate'); - $this->form_validation->set_rules('amount_item[' . $id . ']', 'Ledger Amount', 'trim|currency'); + $this->form_validation->set_rules('dest_stock_item_quantity[' . $id . ']', 'Stock Item Quantity', 'trim|quantity'); + $this->form_validation->set_rules('dest_stock_item_rate_per_unit[' . $id . ']', 'Stock Item Rate Per Unit', 'trim|currency'); + $this->form_validation->set_rules('dest_stock_item_amount[' . $id . ']', 'Stock Item Amount', 'trim|currency'); } }
@@ -597,21 +572,16 @@ class StockTransfer extends Controller { $data['voucher_date']['value'] = $this->input->post('voucher_date', TRUE); $data['voucher_narration']['value'] = $this->input->post('voucher_narration', TRUE); $data['voucher_tag'] = $this->input->post('voucher_tag', TRUE); - $data['has_reconciliation'] = $this->input->post('has_reconciliation', TRUE); - - $data['main_account_active'] = $this->input->post('main_account', TRUE); - $data['main_entity_active'] = $this->input->post('main_entity', TRUE);
- $data['stock_item_id'] = $this->input->post('stock_item_id', TRUE); - $data['stock_item_quantity'] = $this->input->post('stock_item_quantity', TRUE); - $data['stock_item_rate_per_unit'] = $this->input->post('stock_item_rate_per_unit', TRUE); - $data['stock_item_discount'] = $this->input->post('stock_item_discount', TRUE); - $data['stock_item_amount'] = $this->input->post('stock_item_amount', TRUE); + $data['source_stock_item_id'] = $this->input->post('source_stock_item_id', TRUE); + $data['source_stock_item_quantity'] = $this->input->post('source_stock_item_quantity', TRUE); + $data['source_stock_item_rate_per_unit'] = $this->input->post('source_stock_item_rate_per_unit', TRUE); + $data['source_stock_item_amount'] = $this->input->post('source_stock_item_amount', TRUE);
- $data['ledger_dc'] = $this->input->post('ledger_dc', TRUE); - $data['ledger_id'] = $this->input->post('ledger_id', TRUE); - $data['rate_item'] = $this->input->post('rate_item', TRUE); - $data['amount_item'] = $this->input->post('amount_item', TRUE); + $data['dest_stock_item_id'] = $this->input->post('dest_stock_item_id', TRUE); + $data['dest_stock_item_quantity'] = $this->input->post('dest_stock_item_quantity', TRUE); + $data['dest_stock_item_rate_per_unit'] = $this->input->post('dest_stock_item_rate_per_unit', TRUE); + $data['dest_stock_item_amount'] = $this->input->post('dest_stock_item_amount', TRUE); }
if ($this->form_validation->run() == FALSE) @@ -619,21 +589,15 @@ class StockTransfer extends Controller { $this->messages->add(validation_errors(), 'error'); $this->template->load('template', 'inventory/stocktransfer/edit', $data); } else { - $data_main_account = $this->input->post('main_account', TRUE); - $data_main_entity = $this->input->post('main_entity', TRUE); - - $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); - $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); - $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); - $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); - $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); - - $data_all_ledger_id = $this->input->post('ledger_id', TRUE); - $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); - $data_all_rate_item = $this->input->post('rate_item', TRUE); - $data_all_amount_item = $this->input->post('amount_item', TRUE); + $data_all_source_stock_item_id = $this->input->post('source_stock_item_id', TRUE); + $data_all_source_stock_item_quantity = $this->input->post('source_stock_item_quantity', TRUE); + $data_all_source_stock_item_rate_per_unit = $this->input->post('source_stock_item_rate_per_unit', TRUE); + $data_all_source_stock_item_amount = $this->input->post('source_stock_item_amount', TRUE);
- $data_total_amount = 0; + $data_all_dest_stock_item_id = $this->input->post('dest_stock_item_id', TRUE); + $data_all_dest_stock_item_quantity = $this->input->post('dest_stock_item_quantity', TRUE); + $data_all_dest_stock_item_rate_per_unit = $this->input->post('dest_stock_item_rate_per_unit', TRUE); + $data_all_dest_stock_item_amount = $this->input->post('dest_stock_item_amount', TRUE);
/* Setting Stock Item type */ if ($current_voucher_type['stock_voucher_type'] == '1') @@ -641,100 +605,69 @@ class StockTransfer extends Controller { else $data_stock_item_type = 2;
- /* Checking for Valid Stock Ledger A/C - account */ - if ($current_voucher_type['stock_voucher_type'] == '1') - $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 2); - else - $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 3); - $valid_main_account_q = $this->db->get(); - if ($valid_main_account_q->num_rows() < 1) - { - if ($current_voucher_type['stock_voucher_type'] == '1') - $this->messages->add('Invalid Purchase Ledger A/C.', 'error'); - else - $this->messages->add('Invalid Sale Ledger A/C.', 'error'); - $this->template->load('template', 'inventory/stocktransfer/edit', $data); - return; - } - /* Checking for Valid Stock Ledger A/C - entity */ - if ($current_voucher_type['stock_voucher_type'] == '1') - $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 4)->or_where('type', 1); - else - $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 5)->or_where('type', 1); - $valid_main_account_q = $this->db->get(); - if ($valid_main_account_q->num_rows() < 1) - { - if ($current_voucher_type['stock_voucher_type'] == '1') - $this->messages->add('Invalid Creditor (Supplier).', 'error'); - else - $this->messages->add('Invalid Debtor (Customer).', 'error'); - $this->template->load('template', 'inventory/stocktransfer/edit', $data); - return; - } - - /* Checking for Valid Stock Item A/C */ - $stock_item_present = FALSE; - $data_total_stock_amount = 0; - foreach ($data_all_stock_item_id as $id => $stock_data) + /* Checking for Valid Stock Item */ + $source_stock_item_present = FALSE; + $data_total_source_stock_amount = 0; + foreach ($data_all_source_stock_item_id as $id => $stock_data) { - if ($data_all_stock_item_id[$id] < 1) + if ($data_all_source_stock_item_id[$id] < 1) continue;
/* Check for valid stock item id */ - $this->db->from('stock_items')->where('id', $data_all_stock_item_id[$id]); + $this->db->from('stock_items')->where('id', $data_all_source_stock_item_id[$id]); $valid_stock_item_q = $this->db->get(); if ($valid_stock_item_q->num_rows() < 1) { - $this->messages->add('Invalid Stock Item.', 'error'); - $this->template->load('template', 'inventory/stocktransfer/edit', $data); + $this->messages->add('Invalid Source Stock Item.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } - $stock_item_present = TRUE; - $data_total_stock_amount += $data_all_stock_item_amount[$id]; + $source_stock_item_present = TRUE; + $data_total_source_stock_amount += $data_all_source_stock_item_amount[$id]; } - if ( ! $stock_item_present) + if ( ! $source_stock_item_present) { - $this->messages->add('No Stock Item selected.', 'error'); - $this->template->load('template', 'inventory/stocktransfer/edit', $data); + $this->messages->add('No Soruce Stock Item selected.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } - - /* Checking for Valid Ledgers A/C */ - $data_total_ledger_amount = 0; - foreach ($data_all_ledger_dc as $id => $ledger_data) + $dest_stock_item_present = FALSE; + $data_total_dest_stock_amount = 0; + foreach ($data_all_dest_stock_item_id as $id => $stock_data) { - if ($data_all_ledger_id[$id] < 1) + if ($data_all_dest_stock_item_id[$id] < 1) continue;
- /* Check for valid ledger id */ - $this->db->from('ledgers')->where('id', $data_all_ledger_id[$id]); - $valid_ledger_q = $this->db->get(); - if ($valid_ledger_q->num_rows() < 1) + /* Check for valid stock item id */ + $this->db->from('stock_items')->where('id', $data_all_dest_stock_item_id[$id]); + $valid_stock_item_q = $this->db->get(); + if ($valid_stock_item_q->num_rows() < 1) { - $this->messages->add('Invalid Ledger A/C.', 'error'); - $this->template->load('template', 'inventory/stocktransfer/edit', $data); + $this->messages->add('Invalid Destination Stock Item.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } - if ($data_all_ledger_dc[$id] == 'D') - $data_total_ledger_amount += $data_all_amount_item[$id]; - else - $data_total_ledger_amount -= $data_all_amount_item[$id]; + $dest_stock_item_present = TRUE; + $data_total_dest_stock_amount += $data_all_dest_stock_item_amount[$id]; + } + if ( ! $dest_stock_item_present) + { + $this->messages->add('No Destination Stock Item selected.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); + return; }
/* Total amount calculations */ - if ($current_voucher_type['stock_voucher_type'] == '1') + if ($data_total_source_stock_amount < 0) { - $data_main_account_total = $data_total_stock_amount; - $data_main_entity_total = $data_total_stock_amount + $data_total_ledger_amount; - } else { - $data_main_account_total = $data_total_stock_amount + $data_total_ledger_amount; - $data_main_entity_total = $data_total_stock_amount; + $this->messages->add('Source total cannot be negative.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); + return; } - $data_total_amount = $data_total_stock_amount + $data_total_ledger_amount; - if ($data_total_amount < 0) + if ($data_total_dest_stock_amount < 0) { - $this->messages->add($current_voucher_type['name'] . ' Voucher total cannot be negative.', 'error'); - $this->template->load('template', 'inventory/stocktransfer/edit', $data); + $this->messages->add('Destination total cannot be negative.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; }
@@ -754,7 +687,6 @@ class StockTransfer extends Controller { $data_tag = NULL; $data_type = $voucher_type_id; $data_date = date_php_to_mysql($data_date); // Converting date to MySQL - $data_has_reconciliation = $this->input->post('has_reconciliation', TRUE);
$this->db->trans_start(); $update_data = array( @@ -762,17 +694,19 @@ class StockTransfer extends Controller { 'date' => $data_date, 'narration' => $data_narration, 'tag_id' => $data_tag, + 'dr_total' => $data_total_source_stock_amount, + 'cr_total' => $data_total_dest_stock_amount, ); if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) { $this->db->trans_rollback(); - $this->messages->add('Error updating Voucher A/C.', 'error'); + $this->messages->add('Error updating Voucher.', 'error'); $this->logger->write_message("error", "Error updating voucher details for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; }
- /* TODO : Deleting all old ledger data, Bad solution */ + /* TODO : Deleting all old stock item */ if ( ! $this->db->delete('stock_voucher_items', array('voucher_id' => $voucher_id))) { $this->db->trans_rollback(); @@ -782,151 +716,78 @@ class StockTransfer extends Controller { return; }
- if ( ! $this->db->delete('voucher_items', array('voucher_id' => $voucher_id))->where('stock_type', 3)) - { - $this->db->trans_rollback(); - $this->messages->add('Error deleting previous Ledger A/C's from Voucher.', 'error'); - $this->logger->write_message("error", "Error deleting previous voucher items for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); - $this->template->load('template', 'inventory/stocktransfer/edit', $data); - return; - } - - /* Updating main - account */ - $update_data = array( - 'ledger_id' => $data_main_account, - 'amount' => $data_main_account_total, - 'dc' => '', - 'reconciliation_date' => NULL, - 'stock_type' => 1, - 'stock_rate' => '', - ); - if ($current_voucher_type['stock_voucher_type'] == '1') - $update_data['dc'] = 'D'; - else - $update_data['dc'] = 'C'; - if ( ! $this->db->where('voucher_id', $voucher_id)->where('stock_type', 1)->update('voucher_items', $update_data)) - { - $this->db->trans_rollback(); - if ($current_voucher_type['stock_voucher_type'] == '1') - { - $this->messages->add('Error updating Purchase Ledger A/C of Voucher.', 'error'); - $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating purchase ledger " . "[id:" . $data_main_account . "]"); - } else { - $this->messages->add('Error updating Sale Ledger A/C of Voucher.', 'error'); - $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating sale ledger " . "[id:" . $data_main_account . "]"); - } - $this->template->load('template', 'inventory/stocktransfer/edit', $data); - return; - } - - /* Updating main - entity */ - $update_data = array( - 'ledger_id' => $data_main_entity, - 'amount' => $data_main_entity_total, - 'dc' => '', - 'reconciliation_date' => NULL, - 'stock_type' => 2, - 'stock_rate' => '', - ); - if ($current_voucher_type['stock_voucher_type'] == '1') - $insert_data['dc'] = 'C'; - else - $insert_data['dc'] = 'D'; - if ( ! $this->db->where('voucher_id', $voucher_id)->where('stock_type', 2)->update('voucher_items', $update_data)) - { - $this->db->trans_rollback(); - if ($current_voucher_type['stock_voucher_type'] == '1') - { - $this->messages->add('Error updating Creditor (Supplier) of Voucher.', 'error'); - $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating creditor ledger " . "[id:" . $data_main_entity . "]"); - } else { - $this->messages->add('Error updating Debtor (Customer) of Voucher.', 'error'); - $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debtor ledger " . "[id:" . $data_main_entity . "]"); - } - $this->template->load('template', 'inventory/stocktransfer/edit', $data); - return; - } - - /* Adding stock items */ - $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); - $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); - $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); - $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); - $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); + /* Adding source stock items */ + $data_all_source_stock_item_id = $this->input->post('source_stock_item_id', TRUE); + $data_all_source_stock_item_quantity = $this->input->post('source_stock_item_quantity', TRUE); + $data_all_source_stock_item_rate_per_unit = $this->input->post('source_stock_item_rate_per_unit', TRUE); + $data_all_source_stock_item_amount = $this->input->post('source_stock_item_amount', TRUE);
- foreach ($data_all_stock_item_id as $id => $stock_data) + foreach ($data_all_source_stock_item_id as $id => $stock_data) { - $data_stock_item_id = $data_all_stock_item_id[$id]; + $data_source_stock_item_id = $data_all_source_stock_item_id[$id];
- if ($data_stock_item_id < 1) + if ($data_source_stock_item_id < 1) continue;
- $data_stock_item_quantity = $data_all_stock_item_quantity[$id]; - $data_stock_item_rate_per_unit = $data_all_stock_item_rate_per_unit[$id]; - $data_stock_item_discount = $data_all_stock_item_discount[$id]; - $data_stock_item_amount = $data_all_stock_item_amount[$id]; + $data_source_stock_item_quantity = $data_all_source_stock_item_quantity[$id]; + $data_source_stock_item_rate_per_unit = $data_all_source_stock_item_rate_per_unit[$id]; + $data_source_stock_item_amount = $data_all_source_stock_item_amount[$id];
$insert_stock_data = array( 'voucher_id' => $voucher_id, - 'stock_item_id' => $data_stock_item_id, - 'quantity' => $data_stock_item_quantity, - 'rate_per_unit' => $data_stock_item_rate_per_unit, - 'discount' => $data_stock_item_discount, - 'total' => $data_stock_item_amount, - 'type' => $data_stock_item_type, + 'stock_item_id' => $data_source_stock_item_id, + 'quantity' => $data_source_stock_item_quantity, + 'rate_per_unit' => $data_source_stock_item_rate_per_unit, + 'discount' => '', + 'total' => $data_source_stock_item_amount, + 'type' => '2', ); if ( ! $this->db->insert('stock_voucher_items', $insert_stock_data)) { $this->db->trans_rollback(); - $this->messages->add('Error adding Stock Item - ' . $data_ledger_id . ' to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_ledger_id . "]"); - $this->template->load('template', 'inventory/stocktransfer/edit', $data); + $this->messages->add('Error adding Stock Item - ' . $data_source_stock_item_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_source_stock_item_id . "]"); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } }
- /* Adding ledger accounts */ - $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); - $data_all_ledger_id = $this->input->post('ledger_id', TRUE); - $data_all_rate_item = $this->input->post('rate_item', TRUE); - $data_all_amount_item = $this->input->post('amount_item', TRUE); + /* Adding destination stock items */ + $data_all_dest_stock_item_id = $this->input->post('dest_stock_item_id', TRUE); + $data_all_dest_stock_item_quantity = $this->input->post('dest_stock_item_quantity', TRUE); + $data_all_dest_stock_item_rate_per_unit = $this->input->post('dest_stock_item_rate_per_unit', TRUE); + $data_all_dest_stock_item_amount = $this->input->post('dest_stock_item_amount', TRUE);
- foreach ($data_all_ledger_dc as $id => $ledger_data) + foreach ($data_all_dest_stock_item_id as $id => $stock_data) { - $data_ledger_dc = $data_all_ledger_dc[$id]; - $data_ledger_id = $data_all_ledger_id[$id]; + $data_dest_stock_item_id = $data_all_dest_stock_item_id[$id];
- if ($data_ledger_id < 1) + if ($data_dest_stock_item_id < 1) continue;
- $data_rate = $data_all_rate_item[$id]; - $data_amount = $data_all_amount_item[$id]; + $data_dest_stock_item_quantity = $data_all_dest_stock_item_quantity[$id]; + $data_dest_stock_item_rate_per_unit = $data_all_dest_stock_item_rate_per_unit[$id]; + $data_dest_stock_item_amount = $data_all_dest_stock_item_amount[$id];
- $insert_ledger_data = array( + $insert_stock_data = array( 'voucher_id' => $voucher_id, - 'ledger_id' => $data_ledger_id, - 'amount' => $data_amount, - 'dc' => $data_ledger_dc, - 'reconciliation_date' => NULL, - 'stock_type' => 3, - 'stock_rate' => $data_rate, + 'stock_item_id' => $data_dest_stock_item_id, + 'quantity' => $data_dest_stock_item_quantity, + 'rate_per_unit' => $data_dest_stock_item_rate_per_unit, + 'discount' => '', + 'total' => $data_dest_stock_item_amount, + 'type' => '1', ); - if ( ! $this->db->insert('voucher_items', $insert_ledger_data)) + if ( ! $this->db->insert('stock_voucher_items', $insert_stock_data)) { $this->db->trans_rollback(); - $this->messages->add('Error adding Ledger A/C - ' . $data_ledger_id . ' to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting voucher ledger item " . "[id:" . $data_ledger_id . "]"); - $this->template->load('template', 'inventory/stocktransfer/edit', $data); + $this->messages->add('Error adding Stock Item - ' . $data_dest_stock_item_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_dest_stock_item_id . "]"); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } }
- /* Updating Debit and Credit Total - vouchers */ - $update_data = array( - 'dr_total' => $data_total_amount, - 'cr_total' => $data_total_amount, - ); - if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) { $this->db->trans_rollback(); @@ -945,10 +806,7 @@ class StockTransfer extends Controller { $this->session->set_userdata('voucher_updated_type_label', $current_voucher_type['label']); $this->session->set_userdata('voucher_updated_type_name', $current_voucher_type['name']); $this->session->set_userdata('voucher_updated_number', $data_number); - if ($data_has_reconciliation) - $this->session->set_userdata('voucher_updated_has_reconciliation', TRUE); - else - $this->session->set_userdata('voucher_updated_has_reconciliation', FALSE); + $this->session->set_userdata('voucher_updated_has_reconciliation', FALSE);
/* Showing success message in show() method since message is too long for storing it in session */ $this->logger->write_message("success", "Updated " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); diff --git a/system/application/views/inventory/stocktransfer/edit.php b/system/application/views/inventory/stocktransfer/edit.php new file mode 100644 index 0000000..32586d4 --- /dev/null +++ b/system/application/views/inventory/stocktransfer/edit.php @@ -0,0 +1,394 @@ +<script type="text/javascript"> + +$(document).ready(function() { + + /************************ SOURCE STOCK ITEM ***************************/ + /* Stock Item dropdown changed */ + $('.stock-item-dropdown').live('change', function() { + if ($(this).val() == "0") { + $(this).parent().next().children().attr('value', ""); + $(this).parent().next().next().children().attr('value', ""); + $(this).parent().next().next().next().children().attr('value', ""); + $(this).parent().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().next().children().attr('disabled', 'disabled'); + } else { + $(this).parent().next().children().attr('disabled', ''); + $(this).parent().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().next().children().attr('disabled', ''); + $(this).parent().prev().children().trigger('change'); + } + var stockid = $(this).val(); + var rowid = $(this); + if (stockid > 0) { + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/balance') . '/\''; ?> + stockid, + success: function(data) { + rowid.parent().next().next().next().next().next().next().children().text(data); + rowid.parent().next().next().next().next().next().next().children().text(data); + } + }); + + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, + success: function(data) { + var sell_price = parseFloat(data); + if (isNaN(sell_price)) + sell_price = 0; + if (sell_price <= 0) + rowid.parent().next().next().children().val(""); + else + rowid.parent().next().next().children().val(sell_price); + } + }); + } else { + rowid.parent().next().next().next().next().next().next().children().text(""); + } + }); + + $('table td .source-quantity-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev()); + }); + + $('table td .source-rate-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev().prev()); + }); + + var calculateRowTotal = function(itemrow) { + var item_quantity = itemrow.next().children().val(); + var item_rate_per_unit = itemrow.next().next().children().val(); + + item_quantity = parseFloat(item_quantity); + item_rate_per_unit = parseFloat(item_rate_per_unit); + + if ((!isNaN(item_quantity)) && (!isNaN(item_rate_per_unit))) + { + /* calculating total amount for each stock item */ + var item_amount; + item_amount = (item_quantity * item_rate_per_unit); + + /* displaying total amount for each stock item */ + itemrow.next().next().next().children().val(item_amount); + itemrow.next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); + } + $('.source-recalculate').trigger('click'); + } + + $('table td .source-amount-stock-item').live('change', function() { + $('.source-recalculate').trigger('click'); + }); + + /* calculating stock total */ + var calculateSourceStockTotal = function() { + var stock_total = 0; + $('table td .source-amount-stock-item').each(function(index) { + if ($(this).val() != "") + { + var item_amount = parseFloat($(this).val()); + if ( ! isNaN(item_amount)) + stock_total += item_amount; + } + }); + return stock_total; + } + + /* Add stock item row */ + $('table td .addstockrow').live('click', function() { + var cur_obj = this; + var add_image_url = $(cur_obj).attr('src'); + $(cur_obj).attr('src', <?php echo '\'' . asset_url() . 'images/icons/ajax.gif' . '\''; ?>); + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stocktransfer/addstockrow/source') . '\''; ?>, + success: function(data) { + $(cur_obj).parent().parent().after(data); + $(cur_obj).attr('src', add_image_url); + $('.stock-item-dropdown').trigger('change'); + } + }); + }); + + /* Delete stock item row */ + $('table td .deletestockrow').live('click', function() { + $(this).parent().parent().remove(); + }); + + $('.stock-item-dropdown').trigger('change'); + + /* Recalculate Source Total */ + $('table td .source-recalculate').live('click', function() { + var sourceTotal = calculateSourceStockTotal(); + $("table tr #source-total").text(sourceTotal); + if (sourceTotal >= 0) + $("table tr #source-total").css("background-color", "#FFFF99"); + else + $("table tr #source-total").css("background-color", "#FFE9E8"); + }); + + /************************** DEST STOCK ITEM ***************************/ + /* Stock Item dropdown changed */ + $('.stock-item-dropdown').live('change', function() { + if ($(this).val() == "0") { + $(this).parent().next().children().attr('value', ""); + $(this).parent().next().next().children().attr('value', ""); + $(this).parent().next().next().next().children().attr('value', ""); + $(this).parent().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().next().children().attr('disabled', 'disabled'); + } else { + $(this).parent().next().children().attr('disabled', ''); + $(this).parent().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().next().children().attr('disabled', ''); + $(this).parent().prev().children().trigger('change'); + } + var stockid = $(this).val(); + var rowid = $(this); + if (stockid > 0) { + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/balance') . '/\''; ?> + stockid, + success: function(data) { + rowid.parent().next().next().next().next().next().next().children().text(data); + rowid.parent().next().next().next().next().next().next().children().text(data); + } + }); + + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, + success: function(data) { + var sell_price = parseFloat(data); + if (isNaN(sell_price)) + sell_price = 0; + if (sell_price <= 0) + rowid.parent().next().next().children().val(""); + else + rowid.parent().next().next().children().val(sell_price); + } + }); + } else { + rowid.parent().next().next().next().next().next().next().children().text(""); + } + }); + + $('table td .dest-quantity-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev()); + }); + + $('table td .dest-rate-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev().prev()); + }); + + var calculateRowTotal = function(itemrow) { + var item_quantity = itemrow.next().children().val(); + var item_rate_per_unit = itemrow.next().next().children().val(); + + item_quantity = parseFloat(item_quantity); + item_rate_per_unit = parseFloat(item_rate_per_unit); + + if ((!isNaN(item_quantity)) && (!isNaN(item_rate_per_unit))) + { + /* calculating total amount for each stock item */ + var item_amount; + item_amount = (item_quantity * item_rate_per_unit); + + /* displaying total amount for each stock item */ + itemrow.next().next().next().children().val(item_amount); + itemrow.next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); + } + $('.dest-recalculate').trigger('click'); + } + + $('table td .dest-amount-stock-item').live('change', function() { + $('.dest-recalculate').trigger('click'); + }); + + /* calculating stock total */ + var calculateDestStockTotal = function() { + var stock_total = 0; + $('table td .dest-amount-stock-item').each(function(index) { + if ($(this).val() != "") + { + var item_amount = parseFloat($(this).val()); + if ( ! isNaN(item_amount)) + stock_total += item_amount; + } + }); + return stock_total; + } + + /* Add stock item row */ + $('table td .addstockrow').live('click', function() { + var cur_obj = this; + var add_image_url = $(cur_obj).attr('src'); + $(cur_obj).attr('src', <?php echo '\'' . asset_url() . 'images/icons/ajax.gif' . '\''; ?>); + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stocktransfer/addstockrow/dest') . '\''; ?>, + success: function(data) { + $(cur_obj).parent().parent().after(data); + $(cur_obj).attr('src', add_image_url); + $('.stock-item-dropdown').trigger('change'); + } + }); + }); + + /* Delete stock item row */ + $('table td .deletestockrow').live('click', function() { + $(this).parent().parent().remove(); + }); + + /* Recalculate Dest Total */ + $('table td .dest-recalculate').live('click', function() { + var destTotal = calculateDestStockTotal(); + $("table tr #dest-total").text(destTotal); + if (destTotal >= 0) + $("table tr #dest-total").css("background-color", "#FFFF99"); + else + $("table tr #dest-total").css("background-color", "#FFE9E8"); + }); + + $('.stock-item-dropdown').trigger('change'); + $('table td .dest-recalculate').trigger('click'); + $('table td .source-recalculate').trigger('click'); +}); + +</script> + +<?php + echo form_open('inventory/stocktransfer/edit/' . $current_voucher_type['label'] . '/' . $voucher_id); + echo "<p>"; + echo "<span id="tooltip-target-1">"; + echo form_label('Voucher Number', 'voucher_number'); + echo " "; + echo $current_voucher_type['prefix'] . form_input($voucher_number) . $current_voucher_type['suffix']; + echo "</span>"; + echo "<span id="tooltip-content-1">Leave Voucher Number empty for auto numbering</span>"; + echo " "; + echo "<span id="tooltip-target-2">"; + echo form_label('Voucher Date', 'voucher_date'); + echo " "; + echo form_input_date_restrict($voucher_date); + echo "</span>"; + echo "<span id="tooltip-content-2">Date format is " . $this->config->item('account_date_format') . ".</span>"; + echo "</p>"; + + echo "<h3>Source</h3>"; + echo "<table class="voucher-table">"; + echo "<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate Per Unit</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + + foreach ($source_stock_item_id as $i => $row) + { + $source_stock_item_quantity_item = array( + 'name' => 'source_stock_item_quantity[' . $i . ']', + 'id' => 'source_stock_item_quantity[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => isset($source_stock_item_quantity[$i]) ? $source_stock_item_quantity[$i] : '', + 'class' => 'source-quantity-stock-item', + ); + $source_stock_item_rate_per_unit_item = array( + 'name' => 'source_stock_item_rate_per_unit[' . $i . ']', + 'id' => 'source_stock_item_rate_per_unit[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => isset($source_stock_item_rate_per_unit[$i]) ? $source_stock_item_rate_per_unit[$i] : '', + 'class' => 'source-rate-stock-item', + ); + $source_stock_item_amount_item = array( + 'name' => 'source_stock_item_amount[' . $i . ']', + 'id' => 'source_stock_item_amount[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => isset($source_stock_item_amount[$i]) ? $source_stock_item_amount[$i] : '', + 'class' => 'source-amount-stock-item', + ); + echo "<tr>"; + + echo "<td>" . form_input_stock_item('source_stock_item_id[' . $i . ']', isset($source_stock_item_id[$i]) ? $source_stock_item_id[$i] : 0) . "</td>"; + echo "<td>" . form_input($source_stock_item_quantity_item) . "</td>"; + echo "<td>" . form_input($source_stock_item_rate_per_unit_item) . "</td>"; + echo "<td>" . form_input($source_stock_item_amount_item) . "</td>"; + + echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addstockrow')) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deletestockrow')) . "</td>"; + + echo "<td class="source-stock-item-balance"><div></div></td>"; + + echo "</tr>"; + } + echo "<tr id="source-total"><td colspan=3><strong>Total</strong></td><td id="source-total">0</td><td>" . img(array('src' => asset_url() . "images/icons/gear.png", 'border' => '0', 'alt' => 'Recalculate Total', 'class' => 'source-recalculate', 'title' => 'Recalculate Total')) . "</td><td></td><td></td></tr>"; + echo "</table>"; + + echo "<h3>Destination</h3>"; + echo "<table class="voucher-table">"; + echo "<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate Per Unit</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + + foreach ($dest_stock_item_id as $i => $row) + { + $dest_stock_item_quantity_item = array( + 'name' => 'dest_stock_item_quantity[' . $i . ']', + 'id' => 'dest_stock_item_quantity[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => isset($dest_stock_item_quantity[$i]) ? $dest_stock_item_quantity[$i] : '', + 'class' => 'dest-quantity-stock-item', + ); + $dest_stock_item_rate_per_unit_item = array( + 'name' => 'dest_stock_item_rate_per_unit[' . $i . ']', + 'id' => 'dest_stock_item_rate_per_unit[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => isset($dest_stock_item_rate_per_unit[$i]) ? $dest_stock_item_rate_per_unit[$i] : '', + 'class' => 'dest-rate-stock-item', + ); + $dest_stock_item_amount_item = array( + 'name' => 'dest_stock_item_amount[' . $i . ']', + 'id' => 'dest_stock_item_amount[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => isset($dest_stock_item_amount[$i]) ? $dest_stock_item_amount[$i] : '', + 'class' => 'dest-amount-stock-item', + ); + echo "<tr>"; + + echo "<td>" . form_input_stock_item('dest_stock_item_id[' . $i . ']', isset($dest_stock_item_id[$i]) ? $dest_stock_item_id[$i] : 0) . "</td>"; + echo "<td>" . form_input($dest_stock_item_quantity_item) . "</td>"; + echo "<td>" . form_input($dest_stock_item_rate_per_unit_item) . "</td>"; + echo "<td>" . form_input($dest_stock_item_amount_item) . "</td>"; + + echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addstockrow')) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deletestockrow')) . "</td>"; + + echo "<td class="dest-stock-item-balance"><div></div></td>"; + + echo "</tr>"; + } + echo "<tr id="dest-total"><td colspan=3><strong>Total</strong></td><td id="dest-total">0</td><td>" . img(array('src' => asset_url() . "images/icons/gear.png", 'border' => '0', 'alt' => 'Recalculate Total', 'class' => 'dest-recalculate', 'title' => 'Recalculate Total')) . "</td><td></td><td></td></tr>"; + echo "</table>"; + + echo "<br />"; + echo "<br />"; + + echo "<p>"; + echo form_label('Narration', 'voucher_narration'); + echo "<br />"; + echo form_textarea($voucher_narration); + echo "</p>"; + + echo "<p>"; + echo form_label('Tag', 'voucher_tag'); + echo " "; + echo form_dropdown('voucher_tag', $voucher_tags, $voucher_tag); + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Update'); + echo " "; + echo anchor('voucher/show/' . $current_voucher_type['label'], 'Back', array('title' => 'Back to ' . $current_voucher_type['name'] . ' Vouchers')); + echo "</p>"; + + echo form_close(); +
commit 66cd712d147ff0807c2107d5c674ba9a58a3d85b Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sat Mar 12 22:14:53 2011 +0530
Added stock trasfer download, email and print views
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stocktransfer.php b/system/application/controllers/inventory/stocktransfer.php index e8fe15a..6455c42 100644 --- a/system/application/controllers/inventory/stocktransfer.php +++ b/system/application/controllers/inventory/stocktransfer.php @@ -85,7 +85,7 @@ class StockTransfer extends Controller { if ($this->config->item('account_locked') == 1) { $this->messages->add('Account is locked.', 'error'); - redirect('inventory/stockvoucher/show/' . $voucher_type); + redirect('inventory/stocktransfer/show/' . $voucher_type); return; }
@@ -434,7 +434,7 @@ class StockTransfer extends Controller { if ( ! check_access('edit stock voucher')) { $this->messages->add('Permission denied.', 'error'); - redirect('inventory/stockvoucher/show/' . $voucher_type); + redirect('inventory/stocktransfer/show/' . $voucher_type); return; }
@@ -617,7 +617,7 @@ class StockTransfer extends Controller { if ($this->form_validation->run() == FALSE) { $this->messages->add(validation_errors(), 'error'); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); } else { $data_main_account = $this->input->post('main_account', TRUE); $data_main_entity = $this->input->post('main_entity', TRUE); @@ -653,7 +653,7 @@ class StockTransfer extends Controller { $this->messages->add('Invalid Purchase Ledger A/C.', 'error'); else $this->messages->add('Invalid Sale Ledger A/C.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; } /* Checking for Valid Stock Ledger A/C - entity */ @@ -668,7 +668,7 @@ class StockTransfer extends Controller { $this->messages->add('Invalid Creditor (Supplier).', 'error'); else $this->messages->add('Invalid Debtor (Customer).', 'error'); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; }
@@ -686,7 +686,7 @@ class StockTransfer extends Controller { if ($valid_stock_item_q->num_rows() < 1) { $this->messages->add('Invalid Stock Item.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; } $stock_item_present = TRUE; @@ -695,7 +695,7 @@ class StockTransfer extends Controller { if ( ! $stock_item_present) { $this->messages->add('No Stock Item selected.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; }
@@ -712,7 +712,7 @@ class StockTransfer extends Controller { if ($valid_ledger_q->num_rows() < 1) { $this->messages->add('Invalid Ledger A/C.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; } if ($data_all_ledger_dc[$id] == 'D') @@ -734,7 +734,7 @@ class StockTransfer extends Controller { if ($data_total_amount < 0) { $this->messages->add($current_voucher_type['name'] . ' Voucher total cannot be negative.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; }
@@ -768,7 +768,7 @@ class StockTransfer extends Controller { $this->db->trans_rollback(); $this->messages->add('Error updating Voucher A/C.', 'error'); $this->logger->write_message("error", "Error updating voucher details for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; }
@@ -778,7 +778,7 @@ class StockTransfer extends Controller { $this->db->trans_rollback(); $this->messages->add('Error deleting previous stock items from Voucher.', 'error'); $this->logger->write_message("error", "Error deleting previous stock items from " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; }
@@ -787,7 +787,7 @@ class StockTransfer extends Controller { $this->db->trans_rollback(); $this->messages->add('Error deleting previous Ledger A/C's from Voucher.', 'error'); $this->logger->write_message("error", "Error deleting previous voucher items for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; }
@@ -815,7 +815,7 @@ class StockTransfer extends Controller { $this->messages->add('Error updating Sale Ledger A/C of Voucher.', 'error'); $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating sale ledger " . "[id:" . $data_main_account . "]"); } - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; }
@@ -843,7 +843,7 @@ class StockTransfer extends Controller { $this->messages->add('Error updating Debtor (Customer) of Voucher.', 'error'); $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debtor ledger " . "[id:" . $data_main_entity . "]"); } - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; }
@@ -880,7 +880,7 @@ class StockTransfer extends Controller { $this->db->trans_rollback(); $this->messages->add('Error adding Stock Item - ' . $data_ledger_id . ' to Voucher.', 'error'); $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_ledger_id . "]"); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; } } @@ -916,7 +916,7 @@ class StockTransfer extends Controller { $this->db->trans_rollback(); $this->messages->add('Error adding Ledger A/C - ' . $data_ledger_id . ' to Voucher.', 'error'); $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting voucher ledger item " . "[id:" . $data_ledger_id . "]"); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; } } @@ -932,7 +932,7 @@ class StockTransfer extends Controller { $this->db->trans_rollback(); $this->messages->add('Error updating Voucher total.', 'error'); $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debit and credit total"); - $this->template->load('template', 'inventory/stockvoucher/edit', $data); + $this->template->load('template', 'inventory/stocktransfer/edit', $data); return; }
@@ -965,7 +965,7 @@ class StockTransfer extends Controller { if ( ! check_access('delete stock voucher')) { $this->messages->add('Permission denied.', 'error'); - redirect('inventory/stockvoucher/show/' . $voucher_type); + redirect('inventory/stocktransfer/show/' . $voucher_type); return; }
@@ -1029,7 +1029,7 @@ class StockTransfer extends Controller { if ( ! check_access('download stock voucher')) { $this->messages->add('Permission denied.', 'error'); - redirect('inventory/stockvoucher/show/' . $voucher_type); + redirect('inventory/stocktransfer/show/' . $voucher_type); return; }
@@ -1059,45 +1059,29 @@ class StockTransfer extends Controller { return; }
- /* Load current voucher details - account, entity, ledgers */ - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); - $cur_voucher_main_account = $this->db->get(); - if ($cur_voucher_main_account->num_rows() < 1) - { - $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); - } - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); - $cur_voucher_main_entity = $this->db->get(); - if ($cur_voucher_main_entity->num_rows() < 1) - { - $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); - } - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); - $cur_voucher_ledgers = $this->db->get(); - if ($cur_voucher_ledgers->num_rows() < 1) + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 1)->order_by('id', 'asc'); + $cur_voucher_source_stock_items = $this->db->get(); + if ($cur_voucher_source_stock_items->num_rows() < 1) { - $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); + $this->messages->add('Voucher has no associated source stock items.', 'error'); } - - /* Load current stock items details */ - $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); - $cur_voucher_stock_items = $this->db->get(); - if ($cur_voucher_stock_items->num_rows() < 1) + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 2)->order_by('id', 'asc'); + $cur_voucher_dest_stock_items = $this->db->get(); + if ($cur_voucher_dest_stock_items->num_rows() < 1) { - $this->messages->add('Voucher has no associated stock items.', 'error'); + $this->messages->add('Voucher has no associated destination stock items.', 'error'); }
$data['cur_voucher'] = $cur_voucher; - $data['cur_voucher_main_account'] = $cur_voucher_main_account; - $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; - $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; - $data['cur_voucher_stock_items'] = $cur_voucher_stock_items; + $data['cur_voucher_source_stock_items'] = $cur_voucher_source_stock_items; + $data['cur_voucher_dest_stock_items'] = $cur_voucher_dest_stock_items; $data['voucher_type_id'] = $voucher_type_id; $data['current_voucher_type'] = $current_voucher_type;
/* Download Voucher */ $file_name = $current_voucher_type['name'] . '_voucher_' . $cur_voucher->number . ".html"; - $download_data = $this->load->view('inventory/stockvoucher/downloadpreview', $data, TRUE); + $download_data = $this->load->view('inventory/stocktransfer/downloadpreview', $data, TRUE); force_download($file_name, $download_data); return; } @@ -1110,7 +1094,7 @@ class StockTransfer extends Controller { if ( ! check_access('print stock voucher')) { $this->messages->add('Permission denied.', 'error'); - redirect('inventory/stockvoucher/show/' . $voucher_type); + redirect('inventory/stocktransfer/show/' . $voucher_type); return; }
@@ -1140,43 +1124,27 @@ class StockTransfer extends Controller { return; }
- /* Load current voucher details - account, entity, ledgers */ - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); - $cur_voucher_main_account = $this->db->get(); - if ($cur_voucher_main_account->num_rows() < 1) - { - $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); - } - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); - $cur_voucher_main_entity = $this->db->get(); - if ($cur_voucher_main_entity->num_rows() < 1) - { - $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); - } - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); - $cur_voucher_ledgers = $this->db->get(); - if ($cur_voucher_ledgers->num_rows() < 1) + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 1)->order_by('id', 'asc'); + $cur_voucher_source_stock_items = $this->db->get(); + if ($cur_voucher_source_stock_items->num_rows() < 1) { - $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); + $this->messages->add('Voucher has no associated source stock items.', 'error'); } - - /* Load current stock items details */ - $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); - $cur_voucher_stock_items = $this->db->get(); - if ($cur_voucher_stock_items->num_rows() < 1) + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 2)->order_by('id', 'asc'); + $cur_voucher_dest_stock_items = $this->db->get(); + if ($cur_voucher_dest_stock_items->num_rows() < 1) { - $this->messages->add('Voucher has no associated stock items.', 'error'); + $this->messages->add('Voucher has no associated destination stock items.', 'error'); }
$data['cur_voucher'] = $cur_voucher; - $data['cur_voucher_main_account'] = $cur_voucher_main_account; - $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; - $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; - $data['cur_voucher_stock_items'] = $cur_voucher_stock_items; + $data['cur_voucher_source_stock_items'] = $cur_voucher_source_stock_items; + $data['cur_voucher_dest_stock_items'] = $cur_voucher_dest_stock_items; $data['voucher_type_id'] = $voucher_type_id; $data['current_voucher_type'] = $current_voucher_type;
- $this->load->view('inventory/stockvoucher/printpreview', $data); + $this->load->view('inventory/stocktransfer/printpreview', $data); return; }
@@ -1189,7 +1157,7 @@ class StockTransfer extends Controller { if ( ! check_access('email stock voucher')) { $this->messages->add('Permission denied.', 'error'); - redirect('inventory/stockvoucher/show/' . $voucher_type); + redirect('inventory/stocktransfer/show/' . $voucher_type); return; }
@@ -1214,32 +1182,18 @@ class StockTransfer extends Controller { return; }
- /* Load current voucher details - account, entity, ledgers */ - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); - $cur_voucher_main_account = $this->db->get(); - if ($cur_voucher_main_account->num_rows() < 1) - { - $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); - } - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); - $cur_voucher_main_entity = $this->db->get(); - if ($cur_voucher_main_entity->num_rows() < 1) - { - $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); - } - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); - $cur_voucher_ledgers = $this->db->get(); - if ($cur_voucher_ledgers->num_rows() < 1) + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 1)->order_by('id', 'asc'); + $cur_voucher_source_stock_items = $this->db->get(); + if ($cur_voucher_source_stock_items->num_rows() < 1) { - $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); + $this->messages->add('Voucher has no associated source stock items.', 'error'); } - - /* Load current stock items details */ - $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); - $cur_voucher_stock_items = $this->db->get(); - if ($cur_voucher_stock_items->num_rows() < 1) + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 2)->order_by('id', 'asc'); + $cur_voucher_dest_stock_items = $this->db->get(); + if ($cur_voucher_dest_stock_items->num_rows() < 1) { - $this->messages->add('Voucher has no associated stock items.', 'error'); + $this->messages->add('Voucher has no associated destination stock items.', 'error'); }
$data['voucher_type_id'] = $voucher_type_id; @@ -1265,19 +1219,17 @@ class StockTransfer extends Controller { if ($this->form_validation->run() == FALSE) { $data['error'] = validation_errors(); - $this->load->view('inventory/stockvoucher/email', $data); + $this->load->view('inventory/stocktransfer/email', $data); return; } else { $data['cur_voucher'] = $cur_voucher; - $data['cur_voucher_main_account'] = $cur_voucher_main_account; - $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; - $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; - $data['cur_voucher_stock_items'] = $cur_voucher_stock_items; + $data['cur_voucher_source_stock_items'] = $cur_voucher_source_stock_items; + $data['cur_voucher_dest_stock_items'] = $cur_voucher_dest_stock_items;
/* Preparing message */ - $message = $this->load->view('inventory/stockvoucher/emailpreview', $data, TRUE); + $message = $this->load->view('inventory/stocktransfer/emailpreview', $data, TRUE);
/* Getting email configuration */ $config['smtp_timeout'] = '30'; @@ -1309,7 +1261,7 @@ class StockTransfer extends Controller { $data['error'] = "Error sending email. Check you email settings."; $this->logger->write_message("error", "Error emailing " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); } - $this->load->view('inventory/stockvoucher/email', $data); + $this->load->view('inventory/stocktransfer/email', $data); return; } return; diff --git a/system/application/views/inventory/stocktransfer/downloadpreview.php b/system/application/views/inventory/stocktransfer/downloadpreview.php new file mode 100644 index 0000000..3a3d55d --- /dev/null +++ b/system/application/views/inventory/stocktransfer/downloadpreview.php @@ -0,0 +1,125 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<title><?php $current_voucher_type['name']; ?> Voucher Number <?php echo $voucher_number; ?></title> + +<style type="text/css"> + body { + color:#000000; + font:14px "Helvetica Neue","Lucida Grande","Helvetica Neue",Arial,sans-serif; + margin:20px; + padding:0; + } + + #print-account-name { + text-align:center; + font-size:17px; + } + + #print-account-address { + text-align:center; + font-size:14px; + } + + #print-voucher-type { + text-align:center; + font-size:15px; + } + + table.print-voucher-table { + border:1px solid #000000; + border-collapse: collapse; + } + + table.print-voucher-table tr.tr-title { + text-align:left; + border:1px solid #000000; + padding:5px 0 5px 2px; + } + + table.print-voucher-table tr.tr-title th { + padding:5px 0 5px 5px; + } + + table.print-voucher-table td { + padding:5px 0 5px 5px; + } + + table.print-voucher-table td.item { + padding-right:35px; + } + + table.print-voucher-table td.last-item { + padding-right:5px; + } + + table.print-voucher-table tr.tr-total { + border:1px solid #000000; + } +</style> + +</head> +<body> + <div id="print-account-name"><span class="value"><?php echo $this->config->item('account_name'); ?></span></div> + <div id="print-account-address"><span class="value"><?php echo $this->config->item('account_address'); ?></span></div> + <br /> + <div id="print-voucher-type"><span class="value"><?php echo $current_voucher_type['name']; ?> Voucher</span></div> + <br /> + <div id="print-voucher-number"><?php echo $current_voucher_type['name']; ?> Voucher Number : <span class="value"><?php echo full_voucher_number($voucher_type_id, $cur_voucher->number); ?></span></div> + <div id="print-voucher-number"><?php echo $current_voucher_type['name']; ?> Voucher Date : <span class="value"><?php echo date_mysql_to_php_display($cur_voucher->date); ?></span></div> + <br /> + + <h3>Source</h3> + <table class="print-voucher-table"> + <thead> + <tr class="tr-title"><th>Stock Item</th><th>Quantity</th><th>Rate</th><th>Total</th></tr> + </thead> + <tbody> + <?php + $currency = $this->config->item('account_currency_symbol'); + $source_total = 0; + foreach ($cur_voucher_source_stock_items->result() as $row) + { + echo "<tr class=\"tr-stock-item\">"; + echo "<td class=\"item\">" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td class=\"item\">" . $row->quantity . "</td>"; + echo "<td class=\"item\">" . $row->rate_per_unit . "</td>"; + echo "<td class=\"last-item\">" . $row->total . "</td>"; + echo "</tr>"; + $source_total += $row->total; + } + echo "<tr class=\"tr-total\"><td class=\"total-name\" colspan=\"3\">Total</td><td class=\"total-amount\">" . $currency . " " . $source_total . "</td></tr>"; + ?> + </tbody> + </table> + + <br /> + + <h3>Destination</h3> + <table class="print-voucher-table"> + <thead> + <tr class="tr-title"><th>Stock Item</th><th>Quantity</th><th>Rate</th><th>Total</th></tr> + </thead> + <tbody> + <?php + $dest_total = 0; + foreach ($cur_voucher_dest_stock_items->result() as $row) + { + echo "<tr class=\"tr-stock-item\">"; + echo "<td class=\"item\">" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td class=\"item\">" . $row->quantity . "</td>"; + echo "<td class=\"item\">" . $row->rate_per_unit . "</td>"; + echo "<td class=\"last-item\">" . $row->total . "</td>"; + echo "</tr>"; + $dest_total += $row->total; + } + echo "<tr class=\"tr-total\"><td class=\"total-name\" colspan=\"3\">Total</td><td class=\"total-amount\">" . $currency . " " . $dest_total . "</td></tr>"; + ?> + </tbody> + </table> + + <br /> + <div id="print-voucher-narration">Narration : <span class="value"><?php echo $cur_voucher->narration; ?></span></div> + <br /> +</body> +</html> diff --git a/system/application/views/inventory/stocktransfer/email.php b/system/application/views/inventory/stocktransfer/email.php new file mode 100644 index 0000000..5ef5b74 --- /dev/null +++ b/system/application/views/inventory/stocktransfer/email.php @@ -0,0 +1,54 @@ +<style type="text/css"> +#error-box { + border:solid 1px #C34A2C; + background:#FFBABA; + color:#222222; + padding:0 10px 0 10px; + margin:0 0 10px 0; + text-align:left; +} + +#message-box { + border:solid 1px #FFEC8B; + background:#FFF8C6; + color:#222222; + padding:0 10px 0 10px; + margin:0 0 10px 0; + text-align:left; +} +</style> +<?php + if (isset($error) && $error) + { + echo "<div id=\"error-box\">"; + echo "<ul>"; + echo ($error); + echo "</ul>"; + echo "</div>"; + } + + if (isset($message) && $message) + { + echo "<div id=\"message-box\">"; + echo "<ul>"; + echo ($message); + echo "</ul>"; + echo "</div>"; + } + + echo form_open('inventory/stocktransfer/email/' . $current_voucher_type['label'] . "/" . $voucher_id); + + echo "Emailing " . $current_voucher_type['name'] . " Voucher No. " . $voucher_number . "<br />"; + + echo "<p>"; + echo form_label('Email to', 'email_to'); + echo "<br />"; + echo form_input($email_to); + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Send Email'); + echo "</p>"; + + echo form_close(); + diff --git a/system/application/views/inventory/stocktransfer/emailpreview.php b/system/application/views/inventory/stocktransfer/emailpreview.php new file mode 100644 index 0000000..4a279ac --- /dev/null +++ b/system/application/views/inventory/stocktransfer/emailpreview.php @@ -0,0 +1,70 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<title>Email - <?php echo $current_voucher_type['name']; ?> Voucher Number <?php echo full_voucher_number($voucher_type_id, $cur_voucher->number); ?></title> +</head> +<body> + <p><?php echo $this->config->item('account_name'); ?></p> + <p><?php echo $this->config->item('account_address'); ?></p> + <p><strong><?php echo $current_voucher_type['name']; ?> Voucher</strong></p> + <p><?php echo $current_voucher_type['name']; ?> Voucher Number : <strong><?php echo full_voucher_number($voucher_type_id, $cur_voucher->number); ?></strong></p> + <p><?php echo $current_voucher_type['name']; ?> Voucher Date : <strong><?php echo date_mysql_to_php_display($cur_voucher->date); ?></strong></p> + + <br /> + + <h3>Source</h3> + <table border=1 cellpadding=6> + <thead> + <tr><th align="left">Stock Item</th><th>Quantity</th><th>Rate</th><th>Total</th></tr> + </thead> + <tbody> + <?php + $currency = $this->config->item('account_currency_symbol'); + $source_total = 0; + foreach ($cur_voucher_source_stock_items->result() as $row) + { + echo "<tr class=\"tr-stock-item\">"; + echo "<td class=\"item\">" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td class=\"item\">" . $row->quantity . "</td>"; + echo "<td class=\"item\">" . $row->rate_per_unit . "</td>"; + echo "<td class=\"last-item\">" . $row->total . "</td>"; + echo "</tr>"; + $source_total += $row->total; + } + echo "<tr class=\"tr-total\"><td class=\"total-name\" colspan=\"3\">Total</td><td class=\"total-amount\">" . $currency . " " . $source_total . "</td></tr>"; + ?> + </tbody> + </table> + + <br /> + + <h3>Destination</h3> + <table border=1 cellpadding=6> + <thead> + <tr><th align="left">Stock Item</th><th>Quantity</th><th>Rate</th><th>Total</th></tr> + </thead> + <tbody> + <?php + $currency = $this->config->item('account_currency_symbol'); + $source_total = 0; + foreach ($cur_voucher_dest_stock_items->result() as $row) + { + echo "<tr class=\"tr-stock-item\">"; + echo "<td class=\"item\">" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td class=\"item\">" . $row->quantity . "</td>"; + echo "<td class=\"item\">" . $row->rate_per_unit . "</td>"; + echo "<td class=\"last-item\">" . $row->total . "</td>"; + echo "</tr>"; + $source_total += $row->total; + } + echo "<tr class=\"tr-total\"><td class=\"total-name\" colspan=\"3\">Total</td><td class=\"total-amount\">" . $currency . " " . $source_total . "</td></tr>"; + ?> + </tbody> + </table> + + <br /> + + <p>Narration : <span class="value"><?php echo $cur_voucher->narration; ?></p> + <br /> +</body> +</html> diff --git a/system/application/views/inventory/stocktransfer/printpreview.php b/system/application/views/inventory/stocktransfer/printpreview.php new file mode 100644 index 0000000..7b15e00 --- /dev/null +++ b/system/application/views/inventory/stocktransfer/printpreview.php @@ -0,0 +1,74 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<title>Print - <?php echo $current_voucher_type['name']; ?> Voucher Number <?php echo $voucher_number; ?></title> +<?php echo link_tag(asset_url() . 'images/favicon.ico', 'shortcut icon', 'image/ico'); ?> +<link type="text/css" rel="stylesheet" href="<?php echo asset_url(); ?>css/printvoucher.css"> +</head> +<body> + <div id="print-account-name"><span class="value"><?php echo $this->config->item('account_name'); ?></span></div> + <div id="print-account-address"><span class="value"><?php echo $this->config->item('account_address'); ?></span></div> + <br /> + <div id="print-voucher-type"><span class="value"><?php echo $current_voucher_type['name']; ?> Voucher</span></div> + <br /> + <div id="print-voucher-number"><?php echo $current_voucher_type['name']; ?> Voucher Number : <span class="value"><?php echo full_voucher_number($voucher_type_id, $cur_voucher->number); ?></span></div> + <div id="print-voucher-number"><?php echo $current_voucher_type['name']; ?> Voucher Date : <span class="value"><?php echo date_mysql_to_php_display($cur_voucher->date); ?></span></div> + <br /> + + <h3>Source</h3> + <table class="print-voucher-table"> + <thead> + <tr class="tr-title"><th>Stock Item</th><th>Quantity</th><th>Rate</th><th>Total</th></tr> + </thead> + <tbody> + <?php + $currency = $this->config->item('account_currency_symbol'); + $source_total = 0; + foreach ($cur_voucher_source_stock_items->result() as $row) + { + echo "<tr class=\"tr-stock-item\">"; + echo "<td class=\"item\">" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td class=\"item\">" . $row->quantity . "</td>"; + echo "<td class=\"item\">" . $row->rate_per_unit . "</td>"; + echo "<td class=\"last-item\">" . $row->total . "</td>"; + echo "</tr>"; + $source_total += $row->total; + } + echo "<tr class=\"tr-total\"><td class=\"total-name\" colspan=\"3\">Total</td><td class=\"total-amount\">" . $currency . " " . $source_total . "</td></tr>"; + ?> + </tbody> + </table> + + <br /> + + <h3>Destination</h3> + <table class="print-voucher-table"> + <thead> + <tr class="tr-title"><th>Stock Item</th><th>Quantity</th><th>Rate</th><th>Total</th></tr> + </thead> + <tbody> + <?php + $dest_total = 0; + foreach ($cur_voucher_dest_stock_items->result() as $row) + { + echo "<tr class=\"tr-stock-item\">"; + echo "<td class=\"item\">" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td class=\"item\">" . $row->quantity . "</td>"; + echo "<td class=\"item\">" . $row->rate_per_unit . "</td>"; + echo "<td class=\"last-item\">" . $row->total . "</td>"; + echo "</tr>"; + $dest_total += $row->total; + } + echo "<tr class=\"tr-total\"><td class=\"total-name\" colspan=\"3\">Total</td><td class=\"total-amount\">" . $currency . " " . $dest_total . "</td></tr>"; + ?> + </tbody> + </table> + + <br /> + <div id="print-voucher-narration">Narration : <span class="value"><?php echo $cur_voucher->narration; ?></span></div> + <br /> + <form> + <input class="hide-print" type="button" onClick="window.print()" value="Print voucher"> + </form> +</body> +</html>
commit 4e9b7cf14862b72250a70c9f0397f00618223754 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Wed Mar 9 22:57:50 2011 +0530
Updated view stock transfer
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stocktransfer.php b/system/application/controllers/inventory/stocktransfer.php index add65ef..e8fe15a 100644 --- a/system/application/controllers/inventory/stocktransfer.php +++ b/system/application/controllers/inventory/stocktransfer.php @@ -48,42 +48,26 @@ class StockTransfer extends Controller { return; }
- /* Load current voucher details - account, entity, ledgers */ - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); - $cur_voucher_main_account = $this->db->get(); - if ($cur_voucher_main_account->num_rows() < 1) - { - $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); - } - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); - $cur_voucher_main_entity = $this->db->get(); - if ($cur_voucher_main_entity->num_rows() < 1) - { - $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); - } - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); - $cur_voucher_ledgers = $this->db->get(); - if ($cur_voucher_ledgers->num_rows() < 1) + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 1)->order_by('id', 'asc'); + $cur_voucher_source_stock_items = $this->db->get(); + if ($cur_voucher_source_stock_items->num_rows() < 1) { - $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); + $this->messages->add('Voucher has no associated source stock items.', 'error'); } - - /* Load current stock items details */ - $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); - $cur_voucher_stock_items = $this->db->get(); - if ($cur_voucher_stock_items->num_rows() < 1) + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->where('type', 2)->order_by('id', 'asc'); + $cur_voucher_dest_stock_items = $this->db->get(); + if ($cur_voucher_dest_stock_items->num_rows() < 1) { - $this->messages->add('Voucher has no associated stock items.', 'error'); + $this->messages->add('Voucher has no associated destination stock items.', 'error'); }
$data['cur_voucher'] = $cur_voucher; - $data['cur_voucher_main_account'] = $cur_voucher_main_account; - $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; - $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; - $data['cur_voucher_stock_items'] = $cur_voucher_stock_items; + $data['cur_voucher_source_stock_items'] = $cur_voucher_source_stock_items; + $data['cur_voucher_dest_stock_items'] = $cur_voucher_dest_stock_items; $data['voucher_type_id'] = $voucher_type_id; $data['current_voucher_type'] = $current_voucher_type; - $this->template->load('template', 'inventory/stockvoucher/view', $data); + $this->template->load('template', 'inventory/stocktransfer/view', $data); return; }
diff --git a/system/application/views/inventory/stocktransfer/view.php b/system/application/views/inventory/stocktransfer/view.php new file mode 100644 index 0000000..210bb2b --- /dev/null +++ b/system/application/views/inventory/stocktransfer/view.php @@ -0,0 +1,71 @@ +<p>Voucher Number : <span class="bold"><?php echo full_voucher_number($voucher_type_id, $cur_voucher->number); ?></span> + +Voucher Date : <span class="bold"><?php echo date_mysql_to_php_display($cur_voucher->date); ?></span> +</p> + +<h3>Source</h3> +<table border=0 cellpadding=5 class="simple-table voucher-view-table"> +<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate</th><th>Total</th></tr></thead> +<?php +$stock_total = 0; +foreach ($cur_voucher_source_stock_items->result() as $row) +{ + echo "<tr>"; + echo "<td>" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td>" . $row->quantity . "</td>"; + echo "<td>" . $row->rate_per_unit . "</td>"; + echo "<td>" . $row->total . "</td>"; + echo "</tr>"; + $stock_total += $row->total; +} +?> +<tr class="voucher-total"><td colspan=3><strong>Total</strong></td><td id="stock-total"><?php echo convert_cur($stock_total); ?></td></tr> +</table> + +<h3>Destination</h3> +<table border=0 cellpadding=5 class="simple-table voucher-view-table"> +<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate</th><th>Total</th></tr></thead> +<?php +$stock_total = 0; +foreach ($cur_voucher_dest_stock_items->result() as $row) +{ + echo "<tr>"; + echo "<td>" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td>" . $row->quantity . "</td>"; + echo "<td>" . $row->rate_per_unit . "</td>"; + echo "<td>" . $row->total . "</td>"; + echo "</tr>"; + $stock_total += $row->total; +} +?> +<tr class="voucher-total"><td colspan=3><strong>Total</strong></td><td id="stock-total"><?php echo convert_cur($stock_total); ?></td></tr> +</table> + +<br /> + +<p>Narration :<br /> +<span class="bold"><?php echo $cur_voucher->narration; ?></span> +</p> +<p> +Tag : +<?php +$cur_voucher_tag = $this->Tag_model->show_voucher_tag($cur_voucher->tag_id); +if ($cur_voucher_tag == "") + echo "(None)"; +else + echo $cur_voucher_tag; +?> +</p> +<?php + echo anchor('voucher/show/' . $current_voucher_type['label'], 'Back', array('title' => 'Back to ' . $current_voucher_type['name'] . ' Vouchers')); + echo " | "; + echo anchor('inventory/stocktransfer/edit/' . $current_voucher_type['label'] . "/" . $cur_voucher->id, 'Edit', array('title' => 'Edit ' . $current_voucher_type['name'] . ' Voucher')); + echo " | "; + echo anchor('inventory/stocktransfer/delete/' . $current_voucher_type['label'] . "/" . $cur_voucher->id, 'Delete', array('class' => "confirmClick", 'title' => "Delete voucher", 'title' => 'Delete this ' . $current_voucher_type['name'] . ' Voucher')); + echo " | "; + echo anchor_popup('inventory/stocktransfer/printpreview/' . $current_voucher_type['label'] . "/" . $cur_voucher->id, 'Print', array('title' => 'Print this ' . $current_voucher_type['name'] . ' Voucher', 'width' => '600', 'height' => '600')); + echo " | "; + echo anchor_popup('inventory/stocktransfer/email/' . $current_voucher_type['label'] . "/" . $cur_voucher->id, 'Email', array('title' => 'Email this ' . $current_voucher_type['name'] . ' Voucher', 'width' => '400', 'height' => '200')); + echo " | "; + echo anchor('inventory/stocktransfer/download/' . $current_voucher_type['label'] . "/" . $cur_voucher->id, 'Download', array('title' => "Download voucher", 'title' => 'Download this ' . $current_voucher_type['name'] . ' Voucher')); +
commit 5ebbdfe002fcdaec590856dbb5fe084e48b30a06 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Wed Mar 9 22:53:20 2011 +0530
Verified edit stock voucher database transactions
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index 6a10242..ffd887e 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -918,7 +918,8 @@ class StockVoucher extends Controller { return; }
- if ( ! $this->db->delete('voucher_items', array('voucher_id' => $voucher_id))->where('stock_type', 3)) + $this->db->where('stock_type', 3); + if ( ! $this->db->delete('voucher_items', array('voucher_id' => $voucher_id))) { $this->db->trans_rollback(); $this->messages->add('Error deleting previous Ledger A/C's from Voucher.', 'error'); diff --git a/system/application/views/inventory/stockvoucher/edit.php b/system/application/views/inventory/stockvoucher/edit.php index 79ea9b4..d58d6c3 100644 --- a/system/application/views/inventory/stockvoucher/edit.php +++ b/system/application/views/inventory/stockvoucher/edit.php @@ -464,7 +464,7 @@ $(document).ready(function() { echo "</p>";
echo "<p>"; - echo form_submit('submit', 'Create'); + echo form_submit('submit', 'Update'); echo " "; echo anchor('voucher/show/' . $current_voucher_type['label'], 'Back', array('title' => 'Back to ' . $current_voucher_type['name'] . ' Vouchers')); echo "</p>";
commit 00d42a5ec8434faa36a3f0d34c4e28956078bd7c Author: Prashant P Shah pshah.mumbai@gmail.com Date: Tue Mar 8 22:08:02 2011 +0530
Udpate add stock voucher check database transactions
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index 2e84d71..6a10242 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -486,8 +486,8 @@ class StockVoucher extends Controller { if ( ! $this->db->insert('stock_voucher_items', $insert_stock_data)) { $this->db->trans_rollback(); - $this->messages->add('Error adding Stock Item - ' . $data_ledger_id . ' to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_ledger_id . "]"); + $this->messages->add('Error adding Stock Item - ' . $data_stock_item_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_stock_item_id . "]"); $this->template->load('template', 'inventory/stockvoucher/add', $data); return; } @@ -1014,8 +1014,8 @@ class StockVoucher extends Controller { if ( ! $this->db->insert('stock_voucher_items', $insert_stock_data)) { $this->db->trans_rollback(); - $this->messages->add('Error adding Stock Item - ' . $data_ledger_id . ' to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_ledger_id . "]"); + $this->messages->add('Error adding Stock Item - ' . $data_stock_item_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_stock_item_id . "]"); $this->template->load('template', 'inventory/stockvoucher/edit', $data); return; }
commit eae2c95f34c08084d6866d4302f2903104b3a532 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Tue Mar 8 21:38:28 2011 +0530
Updated stock voucher new row to include proper class
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index a24ba74..2e84d71 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -1468,7 +1468,7 @@ class StockVoucher extends Controller { 'maxlength' => '5', 'size' => '5', 'value' => isset($dr_amount[$i]) ? $dr_amount[$i] : "", - 'class' => 'dr-item', + 'class' => 'rate-item', ); $amount_item = array( 'name' => 'amount_item[' . $i . ']', @@ -1476,9 +1476,9 @@ class StockVoucher extends Controller { 'maxlength' => '15', 'size' => '15', 'value' => isset($cr_amount[$i]) ? $cr_amount[$i] : "", - 'class' => 'cr-item', + 'class' => 'amount-item', ); - echo "<tr>"; + echo '<tr class="new-row">'; echo "<td>" . form_dropdown_dc('ledger_dc[' . $i . ']', 'D') . "</td>"; echo "<td>" . form_input_ledger('ledger_id[' . $i . ']', '0') . "</td>"; echo "<td>" . form_input($rate_item) . "</td>"; @@ -1499,7 +1499,7 @@ class StockVoucher extends Controller { 'maxlength' => '15', 'size' => '9', 'value' => '', - 'class' => 'quantity-item', + 'class' => 'quantity-stock-item', ); $stock_item_rate_per_unit = array( 'name' => 'stock_item_rate_per_unit[' . $i . ']', @@ -1507,7 +1507,7 @@ class StockVoucher extends Controller { 'maxlength' => '15', 'size' => '9', 'value' => '', - 'class' => 'rate-item', + 'class' => 'rate-stock-item', ); $stock_item_discount = array( 'name' => 'stock_item_discount[' . $i . ']', @@ -1515,7 +1515,7 @@ class StockVoucher extends Controller { 'maxlength' => '15', 'size' => '9', 'value' => '', - 'class' => 'discount-item', + 'class' => 'discount-stock-item', ); $stock_item_amount = array( 'name' => 'stock_item_amount[' . $i . ']', @@ -1523,7 +1523,7 @@ class StockVoucher extends Controller { 'maxlength' => '15', 'size' => '15', 'value' => '', - 'class' => 'rate-item', + 'class' => 'amount-stock-item', );
echo '<tr class="new-row">'; @@ -1545,5 +1545,5 @@ class StockVoucher extends Controller { } }
-/* End of file voucher.php */ +/* End of file stockvoucher.php */ /* Location: ./system/application/controllers/inventory/stockvoucher.php */
commit 905db5a81b9d2e21fc928b883e5b5a5d8269e63f Author: Prashant P Shah pshah.mumbai@gmail.com Date: Mon Mar 7 22:54:02 2011 +0530
Updated add stock transfer
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stocktransfer.php b/system/application/controllers/inventory/stocktransfer.php index 7be72a4..add65ef 100644 --- a/system/application/controllers/inventory/stocktransfer.php +++ b/system/application/controllers/inventory/stocktransfer.php @@ -235,8 +235,6 @@ class StockTransfer extends Controller { $data_all_dest_stock_item_rate_per_unit = $this->input->post('dest_stock_item_rate_per_unit', TRUE); $data_all_dest_stock_item_amount = $this->input->post('dest_stock_item_amount', TRUE);
- $data_total_amount = 0; - /* Setting Stock Item type */ if ($current_voucher_type['stock_voucher_type'] == '1') $data_stock_item_type = 1; @@ -296,12 +294,6 @@ class StockTransfer extends Controller { }
/* Total amount calculations */ - if ($data_total_source_stock_amount != $data_total_dest_stock_amount) - { - $this->messages->add('Source total does not match with Destination total.', 'error'); - $this->template->load('template', 'inventory/stocktransfer/add', $data); - return; - } if ($data_total_source_stock_amount < 0) { $this->messages->add('Source total cannot be negative.', 'error'); @@ -314,7 +306,6 @@ class StockTransfer extends Controller { $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } - $data_total_amount = $data_total_source_stock_amount;
/* Adding main voucher */ if ($current_voucher_type['numbering'] == '2') @@ -348,8 +339,8 @@ class StockTransfer extends Controller { 'narration' => $data_narration, 'voucher_type' => $data_type, 'tag_id' => $data_tag, - 'dr_total' => $data_total_amount, - 'cr_total' => $data_total_amount, + 'dr_total' => $data_total_source_stock_amount, + 'cr_total' => $data_total_dest_stock_amount, ); if ( ! $this->db->insert('vouchers', $insert_data)) { @@ -1030,14 +1021,6 @@ class StockTransfer extends Controller { redirect('voucher/view/' . $current_voucher_type['label'] . '/' . $voucher_id); return; } - if ( ! $this->db->delete('voucher_items', array('voucher_id' => $voucher_id))) - { - $this->db->trans_rollback(); - $this->messages->add('Error deleting Voucher - Ledger A/C's.', 'error'); - $this->logger->write_message("error", "Error deleting ledger entries for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); - redirect('voucher/view/' . $current_voucher_type['label'] . '/' . $voucher_id); - return; - } if ( ! $this->db->delete('vouchers', array('id' => $voucher_id))) { $this->db->trans_rollback(); diff --git a/system/application/models/ledger_model.php b/system/application/models/ledger_model.php index 53096e5..2807b07 100644 --- a/system/application/models/ledger_model.php +++ b/system/application/models/ledger_model.php @@ -126,6 +126,14 @@ class Ledger_model extends Model { { /* Selecting whether to show debit side Ledger or credit side Ledger */ $current_voucher_type = voucher_type_info($voucher_type_id); + + /* If Stock Transfer */ + if ($current_voucher_type['stock_voucher_type'] == '3') + { + $html = anchor('inventory/stocktransfer/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "[Stock Transfer]", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); + return $html; + } + $ledger_type = 'C';
if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') @@ -151,18 +159,12 @@ class Ledger_model extends Model { if ($current_voucher_type['base_type'] == '1') $html .= anchor('voucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "(" . $ledger->name . ")", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); else - if ($current_voucher_type['stock_voucher_type'] == '3') - $html .= anchor('inventory/stocktransfer/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "(" . $ledger->name . ")", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); - else - $html .= anchor('inventory/stockvoucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "(" . $ledger->name . ")", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); + $html .= anchor('inventory/stockvoucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "(" . $ledger->name . ")", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); else if ($current_voucher_type['base_type'] == '1') $html .= anchor('voucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, $ledger->name, array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); else - if ($current_voucher_type['stock_voucher_type'] == '3') - $html .= anchor('inventory/stocktransfer/view/' . $current_voucher_type['label'] . "/" . $voucher_id, $ledger->name, array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); - else - $html .= anchor('inventory/stockvoucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, $ledger->name, array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); + $html .= anchor('inventory/stockvoucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, $ledger->name, array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); return $html; } return; diff --git a/system/application/views/inventory/stocktransfer/add.php b/system/application/views/inventory/stocktransfer/add.php index e0af0a2..cd31321 100644 --- a/system/application/views/inventory/stocktransfer/add.php +++ b/system/application/views/inventory/stocktransfer/add.php @@ -74,15 +74,15 @@ $(document).ready(function() { itemrow.next().next().next().children().val(item_amount); itemrow.next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); } - $('.recalculate').trigger('click'); + $('.source-recalculate').trigger('click'); }
$('table td .source-amount-stock-item').live('change', function() { - $('.recalculate').trigger('click'); + $('.source-recalculate').trigger('click'); });
/* calculating stock total */ - var calculateStockTotal = function() { + var calculateSourceStockTotal = function() { var stock_total = 0; $('table td .source-amount-stock-item').each(function(index) { if ($(this).val() != "") @@ -117,6 +117,16 @@ $(document).ready(function() {
$('.stock-item-dropdown').trigger('change');
+ /* Recalculate Source Total */ + $('table td .source-recalculate').live('click', function() { + var sourceTotal = calculateSourceStockTotal(); + $("table tr #source-total").text(sourceTotal); + if (sourceTotal >= 0) + $("table tr #source-total").css("background-color", "#FFFF99"); + else + $("table tr #source-total").css("background-color", "#FFE9E8"); + }); + /************************** DEST STOCK ITEM ***************************/ /* Stock Item dropdown changed */ $('.stock-item-dropdown').live('change', function() { @@ -189,15 +199,15 @@ $(document).ready(function() { itemrow.next().next().next().children().val(item_amount); itemrow.next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); } - $('.recalculate').trigger('click'); + $('.dest-recalculate').trigger('click'); }
$('table td .dest-amount-stock-item').live('change', function() { - $('.recalculate').trigger('click'); + $('.dest-recalculate').trigger('click'); });
/* calculating stock total */ - var calculateStockTotal = function() { + var calculateDestStockTotal = function() { var stock_total = 0; $('table td .dest-amount-stock-item').each(function(index) { if ($(this).val() != "") @@ -230,13 +240,25 @@ $(document).ready(function() { $(this).parent().parent().remove(); });
+ /* Recalculate Dest Total */ + $('table td .dest-recalculate').live('click', function() { + var destTotal = calculateDestStockTotal(); + $("table tr #dest-total").text(destTotal); + if (destTotal >= 0) + $("table tr #dest-total").css("background-color", "#FFFF99"); + else + $("table tr #dest-total").css("background-color", "#FFE9E8"); + }); + $('.stock-item-dropdown').trigger('change'); + $('table td .dest-recalculate').trigger('click'); + $('table td .source-recalculate').trigger('click'); });
</script>
<?php - echo form_open('inventory/stockvoucher/add/' . $current_voucher_type['label']); + echo form_open('inventory/stocktransfer/add/' . $current_voucher_type['label']); echo "<p>"; echo "<span id="tooltip-target-1">"; echo form_label('Voucher Number', 'voucher_number'); @@ -297,6 +319,7 @@ $(document).ready(function() {
echo "</tr>"; } + echo "<tr id="source-total"><td colspan=3><strong>Total</strong></td><td id="source-total">0</td><td>" . img(array('src' => asset_url() . "images/icons/gear.png", 'border' => '0', 'alt' => 'Recalculate Total', 'class' => 'source-recalculate', 'title' => 'Recalculate Total')) . "</td><td></td><td></td></tr>"; echo "</table>";
echo "<h3>Destination</h3>"; @@ -343,6 +366,7 @@ $(document).ready(function() {
echo "</tr>"; } + echo "<tr id="dest-total"><td colspan=3><strong>Total</strong></td><td id="dest-total">0</td><td>" . img(array('src' => asset_url() . "images/icons/gear.png", 'border' => '0', 'alt' => 'Recalculate Total', 'class' => 'dest-recalculate', 'title' => 'Recalculate Total')) . "</td><td></td><td></td></tr>"; echo "</table>";
echo "<br />";
commit e5a06b95d56ffd4ad94ac598336586d11a3b3eac Author: Prashant P Shah pshah.mumbai@gmail.com Date: Fri Mar 4 22:42:48 2011 +0530
Updated stock transfer add javascript
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stocktransfer.php b/system/application/controllers/inventory/stocktransfer.php index 6cd1f0a..7be72a4 100644 --- a/system/application/controllers/inventory/stocktransfer.php +++ b/system/application/controllers/inventory/stocktransfer.php @@ -1348,63 +1348,24 @@ class StockTransfer extends Controller { return; }
- function addrow() - { - $i = time() + rand (0, time()) + rand (0, time()) + rand (0, time()); - $rate_item = array( - 'name' => 'rate_item[' . $i . ']', - 'id' => 'rate_item[' . $i . ']', - 'maxlength' => '5', - 'size' => '5', - 'value' => isset($dr_amount[$i]) ? $dr_amount[$i] : "", - 'class' => 'dr-item', - ); - $amount_item = array( - 'name' => 'amount_item[' . $i . ']', - 'id' => 'amount_item[' . $i . ']', - 'maxlength' => '15', - 'size' => '15', - 'value' => isset($cr_amount[$i]) ? $cr_amount[$i] : "", - 'class' => 'cr-item', - ); - echo "<tr>"; - echo "<td>" . form_dropdown_dc('ledger_dc[' . $i . ']', 'D') . "</td>"; - echo "<td>" . form_input_ledger('ledger_id[' . $i . ']', '0') . "</td>"; - echo "<td>" . form_input($rate_item) . "</td>"; - echo "<td>" . form_input($amount_item) . "</td>"; - echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addrow')) . "</td>"; - echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deleterow')) . "</td>"; - echo "<td class="ledger-balance"><div></div></td>"; - echo "</tr>"; - return; - } - - function addstockrow() + function addstockrow($type) { $i = time() + rand (0, time()) + rand (0, time()) + rand (0, time()); $stock_item_quantity = array( - 'name' => 'stock_item_quantity[' . $i . ']', - 'id' => 'stock_item_quantity[' . $i . ']', + 'name' => $type . '_stock_item_quantity[' . $i . ']', + 'id' => $type . '_stock_item_quantity[' . $i . ']', 'maxlength' => '15', 'size' => '9', 'value' => '', - 'class' => 'quantity-item', + 'class' => $type . '-quantity-stock-item', ); $stock_item_rate_per_unit = array( - 'name' => 'stock_item_rate_per_unit[' . $i . ']', - 'id' => 'stock_item_rate_per_unit[' . $i . ']', - 'maxlength' => '15', - 'size' => '9', - 'value' => '', - 'class' => 'rate-item', - ); - $stock_item_discount = array( - 'name' => 'stock_item_discount[' . $i . ']', - 'id' => 'stock_item_discount[' . $i . ']', + 'name' => $type . '_stock_item_rate_per_unit[' . $i . ']', + 'id' => $type . '_stock_item_rate_per_unit[' . $i . ']', 'maxlength' => '15', 'size' => '9', 'value' => '', - 'class' => 'discount-item', + 'class' => $type . '-rate-stock-item', ); $stock_item_amount = array( 'name' => 'stock_item_amount[' . $i . ']', @@ -1412,14 +1373,13 @@ class StockTransfer extends Controller { 'maxlength' => '15', 'size' => '15', 'value' => '', - 'class' => 'rate-item', + 'class' => $type . '-amount-stock-item', );
echo '<tr class="new-row">'; echo "<td>" . form_input_stock_item('stock_item_id[' . $i . ']', 0) . "</td>"; echo "<td>" . form_input($stock_item_quantity) . "</td>"; echo "<td>" . form_input($stock_item_rate_per_unit) . "</td>"; - echo "<td>" . form_input($stock_item_discount) . "</td>"; echo "<td>" . form_input($stock_item_amount) . "</td>"; echo '<td>'; echo img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Stock Item', 'class' => 'addstockrow')); @@ -1434,5 +1394,5 @@ class StockTransfer extends Controller { } }
-/* End of file voucher.php */ +/* End of file stocktransfer.php */ /* Location: ./system/application/controllers/inventory/stocktransfer.php */ diff --git a/system/application/views/inventory/stocktransfer/add.php b/system/application/views/inventory/stocktransfer/add.php index 2ec94f2..e0af0a2 100644 --- a/system/application/views/inventory/stocktransfer/add.php +++ b/system/application/views/inventory/stocktransfer/add.php @@ -2,18 +2,16 @@
$(document).ready(function() {
- /***************************** STOCK ITEM *****************************/ + /************************ SOURCE STOCK ITEM ***************************/ /* Stock Item dropdown changed */ $('.stock-item-dropdown').live('change', function() { if ($(this).val() == "0") { $(this).parent().next().children().attr('value', ""); $(this).parent().next().next().children().attr('value', ""); $(this).parent().next().next().next().children().attr('value', ""); - $(this).parent().next().next().next().next().children().attr('value', ""); $(this).parent().next().children().attr('disabled', 'disabled'); $(this).parent().next().next().children().attr('disabled', 'disabled'); $(this).parent().next().next().next().children().attr('disabled', 'disabled'); - $(this).parent().next().next().next().next().children().attr('disabled', 'disabled'); } else { $(this).parent().next().children().attr('disabled', ''); $(this).parent().next().next().children().attr('disabled', ''); @@ -27,8 +25,8 @@ $(document).ready(function() { $.ajax({ url: <?php echo '\'' . site_url('inventory/stockitem/balance') . '/\''; ?> + stockid, success: function(data) { - rowid.parent().next().next().next().next().next().next().next().children().text(data); - rowid.parent().next().next().next().next().next().next().next().children().text(data); + rowid.parent().next().next().next().next().next().next().children().text(data); + rowid.parent().next().next().next().next().next().next().children().text(data); } });
@@ -45,70 +43,163 @@ $(document).ready(function() { } }); } else { - rowid.parent().next().next().next().next().next().next().next().children().text(""); + rowid.parent().next().next().next().next().next().next().children().text(""); } });
- $('table td .quantity-stock-item').live('change', function() { + $('table td .source-quantity-stock-item').live('change', function() { var rowid = $(this); calculateRowTotal(rowid.parent().prev()); });
- $('table td .rate-stock-item').live('change', function() { + $('table td .source-rate-stock-item').live('change', function() { var rowid = $(this); calculateRowTotal(rowid.parent().prev().prev()); });
- $('table td .discount-stock-item').live('change', function() { - var rowid = $(this); - calculateRowTotal(rowid.parent().prev().prev().prev()); - }); - var calculateRowTotal = function(itemrow) { var item_quantity = itemrow.next().children().val(); var item_rate_per_unit = itemrow.next().next().children().val(); - var item_discount = itemrow.next().next().next().children().val(); - var is_percent = false;
- /* check whether discount is in percent or absolute value */ - if (item_discount != "") { - if (item_discount.match(/%$/)) + item_quantity = parseFloat(item_quantity); + item_rate_per_unit = parseFloat(item_rate_per_unit); + + if ((!isNaN(item_quantity)) && (!isNaN(item_rate_per_unit))) + { + /* calculating total amount for each stock item */ + var item_amount; + item_amount = (item_quantity * item_rate_per_unit); + + /* displaying total amount for each stock item */ + itemrow.next().next().next().children().val(item_amount); + itemrow.next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); + } + $('.recalculate').trigger('click'); + } + + $('table td .source-amount-stock-item').live('change', function() { + $('.recalculate').trigger('click'); + }); + + /* calculating stock total */ + var calculateStockTotal = function() { + var stock_total = 0; + $('table td .source-amount-stock-item').each(function(index) { + if ($(this).val() != "") { - is_percent = true; + var item_amount = parseFloat($(this).val()); + if ( ! isNaN(item_amount)) + stock_total += item_amount; } + }); + return stock_total; + } + + /* Add stock item row */ + $('table td .addstockrow').live('click', function() { + var cur_obj = this; + var add_image_url = $(cur_obj).attr('src'); + $(cur_obj).attr('src', <?php echo '\'' . asset_url() . 'images/icons/ajax.gif' . '\''; ?>); + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stocktransfer/addstockrow/source') . '\''; ?>, + success: function(data) { + $(cur_obj).parent().parent().after(data); + $(cur_obj).attr('src', add_image_url); + $('.stock-item-dropdown').trigger('change'); + } + }); + }); + + /* Delete stock item row */ + $('table td .deletestockrow').live('click', function() { + $(this).parent().parent().remove(); + }); + + $('.stock-item-dropdown').trigger('change'); + + /************************** DEST STOCK ITEM ***************************/ + /* Stock Item dropdown changed */ + $('.stock-item-dropdown').live('change', function() { + if ($(this).val() == "0") { + $(this).parent().next().children().attr('value', ""); + $(this).parent().next().next().children().attr('value', ""); + $(this).parent().next().next().next().children().attr('value', ""); + $(this).parent().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().next().children().attr('disabled', 'disabled'); + } else { + $(this).parent().next().children().attr('disabled', ''); + $(this).parent().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().next().children().attr('disabled', ''); + $(this).parent().prev().children().trigger('change'); } + var stockid = $(this).val(); + var rowid = $(this); + if (stockid > 0) { + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/balance') . '/\''; ?> + stockid, + success: function(data) { + rowid.parent().next().next().next().next().next().next().children().text(data); + rowid.parent().next().next().next().next().next().next().children().text(data); + } + }); + + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, + success: function(data) { + var sell_price = parseFloat(data); + if (isNaN(sell_price)) + sell_price = 0; + if (sell_price <= 0) + rowid.parent().next().next().children().val(""); + else + rowid.parent().next().next().children().val(sell_price); + } + }); + } else { + rowid.parent().next().next().next().next().next().next().children().text(""); + } + }); + + $('table td .dest-quantity-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev()); + }); + + $('table td .dest-rate-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev().prev()); + }); + + var calculateRowTotal = function(itemrow) { + var item_quantity = itemrow.next().children().val(); + var item_rate_per_unit = itemrow.next().next().children().val(); + item_quantity = parseFloat(item_quantity); item_rate_per_unit = parseFloat(item_rate_per_unit); - item_discount = parseFloat(item_discount); - if (isNaN(item_discount)) - item_discount = 0; + if ((!isNaN(item_quantity)) && (!isNaN(item_rate_per_unit))) { /* calculating total amount for each stock item */ var item_amount; - if (is_percent) { - if (item_discount <= 100) - item_amount = ((item_quantity * item_rate_per_unit) * (100 - item_discount)) / 100; - } else { - item_amount = (item_quantity * item_rate_per_unit) - item_discount; - } + item_amount = (item_quantity * item_rate_per_unit); + /* displaying total amount for each stock item */ - itemrow.next().next().next().next().children().val(item_amount); - itemrow.next().next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); + itemrow.next().next().next().children().val(item_amount); + itemrow.next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); } - updateLedgerRowTotal(); $('.recalculate').trigger('click'); }
- $('table td .amount-stock-item').live('change', function() { - updateLedgerRowTotal(); + $('table td .dest-amount-stock-item').live('change', function() { $('.recalculate').trigger('click'); });
/* calculating stock total */ var calculateStockTotal = function() { var stock_total = 0; - $('table td .amount-stock-item').each(function(index) { + $('table td .dest-amount-stock-item').each(function(index) { if ($(this).val() != "") { var item_amount = parseFloat($(this).val()); @@ -125,7 +216,7 @@ $(document).ready(function() { var add_image_url = $(cur_obj).attr('src'); $(cur_obj).attr('src', <?php echo '\'' . asset_url() . 'images/icons/ajax.gif' . '\''; ?>); $.ajax({ - url: <?php echo '\'' . site_url('inventory/stockvoucher/addstockrow') . '\''; ?>, + url: <?php echo '\'' . site_url('inventory/stocktransfer/addstockrow/dest') . '\''; ?>, success: function(data) { $(cur_obj).parent().parent().after(data); $(cur_obj).attr('src', add_image_url);
commit 07c5b5e5d10965fa2cd37f8378239f707b687f58 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Wed Mar 2 22:59:53 2011 +0530
Updated stock transfer add
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stocktransfer.php b/system/application/controllers/inventory/stocktransfer.php index 035494e..6cd1f0a 100644 --- a/system/application/controllers/inventory/stocktransfer.php +++ b/system/application/controllers/inventory/stocktransfer.php @@ -363,38 +363,72 @@ class StockTransfer extends Controller { }
/* Adding source stock items */ - $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); - $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); - $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); - $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); - $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); + $data_all_source_stock_item_id = $this->input->post('source_stock_item_id', TRUE); + $data_all_source_stock_item_quantity = $this->input->post('source_stock_item_quantity', TRUE); + $data_all_source_stock_item_rate_per_unit = $this->input->post('source_stock_item_rate_per_unit', TRUE); + $data_all_source_stock_item_amount = $this->input->post('source_stock_item_amount', TRUE);
- foreach ($data_all_stock_item_id as $id => $stock_data) + foreach ($data_all_source_stock_item_id as $id => $stock_data) { - $data_stock_item_id = $data_all_stock_item_id[$id]; + $data_source_stock_item_id = $data_all_source_stock_item_id[$id];
- if ($data_stock_item_id < 1) + if ($data_source_stock_item_id < 1) continue;
- $data_stock_item_quantity = $data_all_stock_item_quantity[$id]; - $data_stock_item_rate_per_unit = $data_all_stock_item_rate_per_unit[$id]; - $data_stock_item_discount = $data_all_stock_item_discount[$id]; - $data_stock_item_amount = $data_all_stock_item_amount[$id]; + $data_source_stock_item_quantity = $data_all_source_stock_item_quantity[$id]; + $data_source_stock_item_rate_per_unit = $data_all_source_stock_item_rate_per_unit[$id]; + $data_source_stock_item_amount = $data_all_source_stock_item_amount[$id];
$insert_stock_data = array( 'voucher_id' => $voucher_id, - 'stock_item_id' => $data_stock_item_id, - 'quantity' => $data_stock_item_quantity, - 'rate_per_unit' => $data_stock_item_rate_per_unit, - 'discount' => $data_stock_item_discount, - 'total' => $data_stock_item_amount, - 'type' => $data_stock_item_type, + 'stock_item_id' => $data_source_stock_item_id, + 'quantity' => $data_source_stock_item_quantity, + 'rate_per_unit' => $data_source_stock_item_rate_per_unit, + 'discount' => '', + 'total' => $data_source_stock_item_amount, + 'type' => '2', ); if ( ! $this->db->insert('stock_voucher_items', $insert_stock_data)) { $this->db->trans_rollback(); - $this->messages->add('Error adding Stock Item - ' . $data_ledger_id . ' to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_ledger_id . "]"); + $this->messages->add('Error adding Stock Item - ' . $data_source_stock_item_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_source_stock_item_id . "]"); + $this->template->load('template', 'inventory/stocktransfer/add', $data); + return; + } + } + + /* Adding destination stock items */ + $data_all_dest_stock_item_id = $this->input->post('dest_stock_item_id', TRUE); + $data_all_dest_stock_item_quantity = $this->input->post('dest_stock_item_quantity', TRUE); + $data_all_dest_stock_item_rate_per_unit = $this->input->post('dest_stock_item_rate_per_unit', TRUE); + $data_all_dest_stock_item_amount = $this->input->post('dest_stock_item_amount', TRUE); + + foreach ($data_all_dest_stock_item_id as $id => $stock_data) + { + $data_dest_stock_item_id = $data_all_dest_stock_item_id[$id]; + + if ($data_dest_stock_item_id < 1) + continue; + + $data_dest_stock_item_quantity = $data_all_dest_stock_item_quantity[$id]; + $data_dest_stock_item_rate_per_unit = $data_all_dest_stock_item_rate_per_unit[$id]; + $data_dest_stock_item_amount = $data_all_dest_stock_item_amount[$id]; + + $insert_stock_data = array( + 'voucher_id' => $voucher_id, + 'stock_item_id' => $data_dest_stock_item_id, + 'quantity' => $data_dest_stock_item_quantity, + 'rate_per_unit' => $data_dest_stock_item_rate_per_unit, + 'discount' => '', + 'total' => $data_dest_stock_item_amount, + 'type' => '1', + ); + if ( ! $this->db->insert('stock_voucher_items', $insert_stock_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error adding Stock Item - ' . $data_dest_stock_item_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_dest_stock_item_id . "]"); $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } @@ -414,7 +448,6 @@ class StockTransfer extends Controller { /* Showing success message in show() method since message is too long for storing it in session */ $this->logger->write_message("success", "Added " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); redirect('voucher/show/' . $current_voucher_type['label']); - $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } return; diff --git a/system/application/controllers/voucher.php b/system/application/controllers/voucher.php index 312728f..f3b2e27 100644 --- a/system/application/controllers/voucher.php +++ b/system/application/controllers/voucher.php @@ -52,7 +52,10 @@ class Voucher extends Controller { if ($current_voucher_type['base_type'] == '1') $this->template->set('nav_links', array('voucher/add/' . $current_voucher_type['label'] => 'New ' . $current_voucher_type['name'] . ' Voucher')); else - $this->template->set('nav_links', array('inventory/stockvoucher/add/' . $current_voucher_type['label'] => 'New ' . $current_voucher_type['name'] . ' Voucher')); + if ($current_voucher_type['stock_voucher_type'] == '3') + $this->template->set('nav_links', array('inventory/stocktransfer/add/' . $current_voucher_type['label'] => 'New ' . $current_voucher_type['name'] . ' Voucher')); + else + $this->template->set('nav_links', array('inventory/stockvoucher/add/' . $current_voucher_type['label'] => 'New ' . $current_voucher_type['name'] . ' Voucher')); } }
commit 58d781d7b325efc0f4fe6c173574f802740d9439 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Tue Mar 1 23:09:46 2011 +0530
Added basic add stock transfer voucher
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stocktransfer.php b/system/application/controllers/inventory/stocktransfer.php index 1dec9bd..035494e 100644 --- a/system/application/controllers/inventory/stocktransfer.php +++ b/system/application/controllers/inventory/stocktransfer.php @@ -161,25 +161,25 @@ class StockTransfer extends Controller { $this->form_validation->set_rules('voucher_date', 'Voucher Date', 'trim|required|is_date|is_date_within_range'); if ($current_voucher_type['stock_voucher_type'] == '3') { - + /* TODO */ } $this->form_validation->set_rules('voucher_narration', 'trim'); $this->form_validation->set_rules('voucher_tag', 'Tag', 'trim|is_natural');
- /* Debit and Credit amount validation */ + /* stock item validation */ if ($_POST) { - foreach ($this->input->post('stock_item_id', TRUE) as $id => $stock_data) + foreach ($this->input->post('source_stock_item_id', TRUE) as $id => $stock_data) { - $this->form_validation->set_rules('stock_item_quantity[' . $id . ']', 'Stock Item Quantity', 'trim|quantity'); - $this->form_validation->set_rules('stock_item_rate_per_unit[' . $id . ']', 'Stock Item Rate Per Unit', 'trim|currency'); - $this->form_validation->set_rules('stock_item_discount[' . $id . ']', 'Stock Item Discount', 'trim|discount'); - $this->form_validation->set_rules('stock_item_amount[' . $id . ']', 'Stock Item Amount', 'trim|currency'); + $this->form_validation->set_rules('source_stock_item_quantity[' . $id . ']', 'Stock Item Quantity', 'trim|quantity'); + $this->form_validation->set_rules('source_stock_item_rate_per_unit[' . $id . ']', 'Stock Item Rate Per Unit', 'trim|currency'); + $this->form_validation->set_rules('source_stock_item_amount[' . $id . ']', 'Stock Item Amount', 'trim|currency'); } - foreach ($this->input->post('ledger_dc', TRUE) as $id => $ledger_data) + foreach ($this->input->post('dest_stock_item_id', TRUE) as $id => $stock_data) { - $this->form_validation->set_rules('rate_item[' . $id . ']', 'Rate %', 'trim|rate'); - $this->form_validation->set_rules('amount_item[' . $id . ']', 'Ledger Amount', 'trim|currency'); + $this->form_validation->set_rules('dest_stock_item_quantity[' . $id . ']', 'Stock Item Quantity', 'trim|quantity'); + $this->form_validation->set_rules('dest_stock_item_rate_per_unit[' . $id . ']', 'Stock Item Rate Per Unit', 'trim|currency'); + $this->form_validation->set_rules('dest_stock_item_amount[' . $id . ']', 'Stock Item Amount', 'trim|currency'); } }
@@ -191,58 +191,49 @@ class StockTransfer extends Controller { $data['voucher_narration']['value'] = $this->input->post('voucher_narration', TRUE); $data['voucher_tag'] = $this->input->post('voucher_tag', TRUE);
- $data['main_account_active'] = $this->input->post('main_account', TRUE); - $data['main_entity_active'] = $this->input->post('main_entity', TRUE); - - $data['stock_item_id'] = $this->input->post('stock_item_id', TRUE); - $data['stock_item_quantity'] = $this->input->post('stock_item_quantity', TRUE); - $data['stock_item_rate_per_unit'] = $this->input->post('stock_item_rate_per_unit', TRUE); - $data['stock_item_discount'] = $this->input->post('stock_item_discount', TRUE); - $data['stock_item_amount'] = $this->input->post('stock_item_amount', TRUE); + $data['source_stock_item_id'] = $this->input->post('source_stock_item_id', TRUE); + $data['source_stock_item_quantity'] = $this->input->post('source_stock_item_quantity', TRUE); + $data['source_stock_item_rate_per_unit'] = $this->input->post('source_stock_item_rate_per_unit', TRUE); + $data['source_stock_item_amount'] = $this->input->post('source_stock_item_amount', TRUE);
- $data['ledger_dc'] = $this->input->post('ledger_dc', TRUE); - $data['ledger_id'] = $this->input->post('ledger_id', TRUE); - $data['rate_item'] = $this->input->post('rate_item', TRUE); - $data['amount_item'] = $this->input->post('amount_item', TRUE); + $data['dest_stock_item_id'] = $this->input->post('dest_stock_item_id', TRUE); + $data['dest_stock_item_quantity'] = $this->input->post('dest_stock_item_quantity', TRUE); + $data['dest_stock_item_rate_per_unit'] = $this->input->post('dest_stock_item_rate_per_unit', TRUE); + $data['dest_stock_item_amount'] = $this->input->post('dest_stock_item_amount', TRUE); } else { for ($count = 0; $count <= 3; $count++) { - $data['stock_item_id'][$count] = '0'; - $data['stock_item_quantity'][$count] = ''; - $data['stock_item_rate_per_unit'][$count] = ''; - $data['stock_item_discount'][$count] = ''; - $data['stock_item_amount'][$count] = ''; + $data['source_stock_item_id'][$count] = '0'; + $data['source_stock_item_quantity'][$count] = ''; + $data['source_stock_item_rate_per_unit'][$count] = ''; + $data['source_stock_item_amount'][$count] = ''; } - for ($count = 0; $count <= 1; $count++) + for ($count = 0; $count <= 3; $count++) { - $data['ledger_dc'][$count] = "D"; - $data['ledger_id'][$count] = 0; - $data['rate_item'][$count] = ""; - $data['amount_item'][$count] = ""; + $data['dest_stock_item_id'][$count] = '0'; + $data['dest_stock_item_quantity'][$count] = ''; + $data['dest_stock_item_rate_per_unit'][$count] = ''; + $data['dest_stock_item_amount'][$count] = ''; } }
if ($this->form_validation->run() == FALSE) { $this->messages->add(validation_errors(), 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } else { - $data_main_account = $this->input->post('main_account', TRUE); - $data_main_entity = $this->input->post('main_entity', TRUE); + $data_all_source_stock_item_id = $this->input->post('source_stock_item_id', TRUE); + $data_all_source_stock_item_quantity = $this->input->post('source_stock_item_quantity', TRUE); + $data_all_source_stock_item_rate_per_unit = $this->input->post('source_stock_item_rate_per_unit', TRUE); + $data_all_source_stock_item_amount = $this->input->post('source_stock_item_amount', TRUE);
- $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); - $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); - $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); - $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); - $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); - - $data_all_ledger_id = $this->input->post('ledger_id', TRUE); - $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); - $data_all_rate_item = $this->input->post('rate_item', TRUE); - $data_all_amount_item = $this->input->post('amount_item', TRUE); + $data_all_dest_stock_item_id = $this->input->post('dest_stock_item_id', TRUE); + $data_all_dest_stock_item_quantity = $this->input->post('dest_stock_item_quantity', TRUE); + $data_all_dest_stock_item_rate_per_unit = $this->input->post('dest_stock_item_rate_per_unit', TRUE); + $data_all_dest_stock_item_amount = $this->input->post('dest_stock_item_amount', TRUE);
$data_total_amount = 0;
@@ -252,102 +243,78 @@ class StockTransfer extends Controller { else $data_stock_item_type = 2;
- /* Checking for Valid Stock Ledger A/C - account */ - if ($current_voucher_type['stock_voucher_type'] == '1') - $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 2); - else - $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 3); - $valid_main_account_q = $this->db->get(); - if ($valid_main_account_q->num_rows() < 1) + /* Checking for Valid Stock Item */ + $source_stock_item_present = FALSE; + $data_total_source_stock_amount = 0; + foreach ($data_all_source_stock_item_id as $id => $stock_data) { - if ($current_voucher_type['stock_voucher_type'] == '1') - $this->messages->add('Invalid Purchase Ledger A/C.', 'error'); - else - $this->messages->add('Invalid Sale Ledger A/C.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } - /* Checking for Valid Stock Ledger A/C - entity */ - if ($current_voucher_type['stock_voucher_type'] == '1') - $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 4)->or_where('type', 1); - else - $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 5)->or_where('type', 1); - $valid_main_account_q = $this->db->get(); - if ($valid_main_account_q->num_rows() < 1) - { - if ($current_voucher_type['stock_voucher_type'] == '1') - $this->messages->add('Invalid Creditor (Supplier).', 'error'); - else - $this->messages->add('Invalid Debtor (Customer).', 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } - - /* Checking for Valid Stock Item A/C */ - $stock_item_present = FALSE; - $data_total_stock_amount = 0; - foreach ($data_all_stock_item_id as $id => $stock_data) - { - if ($data_all_stock_item_id[$id] < 1) + if ($data_all_source_stock_item_id[$id] < 1) continue;
/* Check for valid stock item id */ - $this->db->from('stock_items')->where('id', $data_all_stock_item_id[$id]); + $this->db->from('stock_items')->where('id', $data_all_source_stock_item_id[$id]); $valid_stock_item_q = $this->db->get(); if ($valid_stock_item_q->num_rows() < 1) { - $this->messages->add('Invalid Stock Item.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); + $this->messages->add('Invalid Source Stock Item.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } - $stock_item_present = TRUE; - $data_total_stock_amount += $data_all_stock_item_amount[$id]; + $source_stock_item_present = TRUE; + $data_total_source_stock_amount += $data_all_source_stock_item_amount[$id]; } - if ( ! $stock_item_present) + if ( ! $source_stock_item_present) { - $this->messages->add('No Stock Item selected.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); + $this->messages->add('No Soruce Stock Item selected.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } - - /* Checking for Valid Ledgers A/C */ - $data_total_ledger_amount = 0; - foreach ($data_all_ledger_dc as $id => $ledger_data) + $dest_stock_item_present = FALSE; + $data_total_dest_stock_amount = 0; + foreach ($data_all_dest_stock_item_id as $id => $stock_data) { - if ($data_all_ledger_id[$id] < 1) + if ($data_all_dest_stock_item_id[$id] < 1) continue;
- /* Check for valid ledger id */ - $this->db->from('ledgers')->where('id', $data_all_ledger_id[$id]); - $valid_ledger_q = $this->db->get(); - if ($valid_ledger_q->num_rows() < 1) + /* Check for valid stock item id */ + $this->db->from('stock_items')->where('id', $data_all_dest_stock_item_id[$id]); + $valid_stock_item_q = $this->db->get(); + if ($valid_stock_item_q->num_rows() < 1) { - $this->messages->add('Invalid Ledger A/C.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); + $this->messages->add('Invalid Destination Stock Item.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } - if ($data_all_ledger_dc[$id] == 'D') - $data_total_ledger_amount += $data_all_amount_item[$id]; - else - $data_total_ledger_amount -= $data_all_amount_item[$id]; + $dest_stock_item_present = TRUE; + $data_total_dest_stock_amount += $data_all_dest_stock_item_amount[$id]; + } + if ( ! $dest_stock_item_present) + { + $this->messages->add('No Destination Stock Item selected.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); + return; }
/* Total amount calculations */ - if ($current_voucher_type['stock_voucher_type'] == '1') + if ($data_total_source_stock_amount != $data_total_dest_stock_amount) { - $data_main_account_total = $data_total_stock_amount; - $data_main_entity_total = $data_total_stock_amount + $data_total_ledger_amount; - } else { - $data_main_account_total = $data_total_stock_amount + $data_total_ledger_amount; - $data_main_entity_total = $data_total_stock_amount; + $this->messages->add('Source total does not match with Destination total.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); + return; } - $data_total_amount = $data_total_stock_amount + $data_total_ledger_amount; - if ($data_total_amount < 0) + if ($data_total_source_stock_amount < 0) { - $this->messages->add($current_voucher_type['name'] . ' Voucher total cannot be negative.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); + $this->messages->add('Source total cannot be negative.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } + if ($data_total_dest_stock_amount < 0) + { + $this->messages->add('Destination total cannot be negative.', 'error'); + $this->template->load('template', 'inventory/stocktransfer/add', $data); + return; + } + $data_total_amount = $data_total_source_stock_amount;
/* Adding main voucher */ if ($current_voucher_type['numbering'] == '2') @@ -381,81 +348,21 @@ class StockTransfer extends Controller { 'narration' => $data_narration, 'voucher_type' => $data_type, 'tag_id' => $data_tag, + 'dr_total' => $data_total_amount, + 'cr_total' => $data_total_amount, ); if ( ! $this->db->insert('vouchers', $insert_data)) { $this->db->trans_rollback(); $this->messages->add('Error addding Voucher.', 'error'); $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting voucher"); - $this->template->load('template', 'inventory/stockvoucher/add', $data); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } else { $voucher_id = $this->db->insert_id(); }
- /* Adding main - account */ - $insert_data = array( - 'voucher_id' => $voucher_id, - 'ledger_id' => $data_main_account, - 'amount' => $data_main_account_total, - 'dc' => '', - 'reconciliation_date' => NULL, - 'stock_type' => 1, - 'stock_rate' => '', - ); - if ($current_voucher_type['stock_voucher_type'] == '1') - $insert_data['dc'] = 'D'; - else - $insert_data['dc'] = 'C'; - if ( ! $this->db->insert('voucher_items', $insert_data)) - { - $this->db->trans_rollback(); - if ($current_voucher_type['stock_voucher_type'] == '1') - { - $this->messages->add('Error adding Purchase Ledger A/C to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting purchase ledger " . "[id:" . $data_main_account . "]"); - } else { - $this->messages->add('Error adding Sale Ledger A/C to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting sale ledger " . "[id:" . $data_main_account . "]"); - } - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } else { - $main_voucher_id = $this->db->insert_id(); - } - - /* Adding main - entity */ - $insert_data = array( - 'voucher_id' => $voucher_id, - 'ledger_id' => $data_main_entity, - 'amount' => $data_main_entity_total, - 'dc' => '', - 'reconciliation_date' => NULL, - 'stock_type' => 2, - 'stock_rate' => '', - ); - if ($current_voucher_type['stock_voucher_type'] == '1') - $insert_data['dc'] = 'C'; - else - $insert_data['dc'] = 'D'; - if ( ! $this->db->insert('voucher_items', $insert_data)) - { - $this->db->trans_rollback(); - if ($current_voucher_type['stock_voucher_type'] == '1') - { - $this->messages->add('Error adding Creditor (Supplier) to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting creditor ledger " . "[id:" . $data_main_entity . "]"); - } else { - $this->messages->add('Error adding Debtor (Customer) - to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting debtor ledger " . "[id:" . $data_main_entity . "]"); - } - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } else { - $entity_voucher_id = $this->db->insert_id(); - } - - /* Adding stock items */ + /* Adding source stock items */ $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); @@ -488,62 +395,11 @@ class StockTransfer extends Controller { $this->db->trans_rollback(); $this->messages->add('Error adding Stock Item - ' . $data_ledger_id . ' to Voucher.', 'error'); $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_ledger_id . "]"); - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } - } - - /* Adding ledger accounts */ - $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); - $data_all_ledger_id = $this->input->post('ledger_id', TRUE); - $data_all_rate_item = $this->input->post('rate_item', TRUE); - $data_all_amount_item = $this->input->post('amount_item', TRUE); - - foreach ($data_all_ledger_dc as $id => $ledger_data) - { - $data_ledger_dc = $data_all_ledger_dc[$id]; - $data_ledger_id = $data_all_ledger_id[$id]; - - if ($data_ledger_id < 1) - continue; - - $data_rate = $data_all_rate_item[$id]; - $data_amount = $data_all_amount_item[$id]; - - $insert_ledger_data = array( - 'voucher_id' => $voucher_id, - 'ledger_id' => $data_ledger_id, - 'amount' => $data_amount, - 'dc' => $data_ledger_dc, - 'reconciliation_date' => NULL, - 'stock_type' => 3, - 'stock_rate' => $data_rate, - ); - if ( ! $this->db->insert('voucher_items', $insert_ledger_data)) - { - $this->db->trans_rollback(); - $this->messages->add('Error adding Ledger A/C - ' . $data_ledger_id . ' to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting voucher ledger item " . "[id:" . $data_ledger_id . "]"); - $this->template->load('template', 'inventory/stockvoucher/add', $data); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } }
- /* Updating Debit and Credit Total - vouchers */ - $update_data = array( - 'dr_total' => $data_total_amount, - 'cr_total' => $data_total_amount, - ); - - if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) - { - $this->db->trans_rollback(); - $this->messages->add('Error updating Voucher total.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debit and credit total"); - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } - /* Success */ $this->db->trans_complete();
@@ -558,7 +414,7 @@ class StockTransfer extends Controller { /* Showing success message in show() method since message is too long for storing it in session */ $this->logger->write_message("success", "Added " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); redirect('voucher/show/' . $current_voucher_type['label']); - $this->template->load('template', 'inventory/stockvoucher/add', $data); + $this->template->load('template', 'inventory/stocktransfer/add', $data); return; } return; diff --git a/system/application/views/inventory/stocktransfer/add.php b/system/application/views/inventory/stocktransfer/add.php new file mode 100644 index 0000000..2ec94f2 --- /dev/null +++ b/system/application/views/inventory/stocktransfer/add.php @@ -0,0 +1,279 @@ +<script type="text/javascript"> + +$(document).ready(function() { + + /***************************** STOCK ITEM *****************************/ + /* Stock Item dropdown changed */ + $('.stock-item-dropdown').live('change', function() { + if ($(this).val() == "0") { + $(this).parent().next().children().attr('value', ""); + $(this).parent().next().next().children().attr('value', ""); + $(this).parent().next().next().next().children().attr('value', ""); + $(this).parent().next().next().next().next().children().attr('value', ""); + $(this).parent().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().next().next().children().attr('disabled', 'disabled'); + } else { + $(this).parent().next().children().attr('disabled', ''); + $(this).parent().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().next().children().attr('disabled', ''); + $(this).parent().prev().children().trigger('change'); + } + var stockid = $(this).val(); + var rowid = $(this); + if (stockid > 0) { + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/balance') . '/\''; ?> + stockid, + success: function(data) { + rowid.parent().next().next().next().next().next().next().next().children().text(data); + rowid.parent().next().next().next().next().next().next().next().children().text(data); + } + }); + + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, + success: function(data) { + var sell_price = parseFloat(data); + if (isNaN(sell_price)) + sell_price = 0; + if (sell_price <= 0) + rowid.parent().next().next().children().val(""); + else + rowid.parent().next().next().children().val(sell_price); + } + }); + } else { + rowid.parent().next().next().next().next().next().next().next().children().text(""); + } + }); + + $('table td .quantity-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev()); + }); + + $('table td .rate-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev().prev()); + }); + + $('table td .discount-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev().prev().prev()); + }); + + var calculateRowTotal = function(itemrow) { + var item_quantity = itemrow.next().children().val(); + var item_rate_per_unit = itemrow.next().next().children().val(); + var item_discount = itemrow.next().next().next().children().val(); + var is_percent = false; + + /* check whether discount is in percent or absolute value */ + if (item_discount != "") { + if (item_discount.match(/%$/)) + { + is_percent = true; + } + } + item_quantity = parseFloat(item_quantity); + item_rate_per_unit = parseFloat(item_rate_per_unit); + item_discount = parseFloat(item_discount); + if (isNaN(item_discount)) + item_discount = 0; + if ((!isNaN(item_quantity)) && (!isNaN(item_rate_per_unit))) + { + /* calculating total amount for each stock item */ + var item_amount; + if (is_percent) { + if (item_discount <= 100) + item_amount = ((item_quantity * item_rate_per_unit) * (100 - item_discount)) / 100; + } else { + item_amount = (item_quantity * item_rate_per_unit) - item_discount; + } + /* displaying total amount for each stock item */ + itemrow.next().next().next().next().children().val(item_amount); + itemrow.next().next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); + } + updateLedgerRowTotal(); + $('.recalculate').trigger('click'); + } + + $('table td .amount-stock-item').live('change', function() { + updateLedgerRowTotal(); + $('.recalculate').trigger('click'); + }); + + /* calculating stock total */ + var calculateStockTotal = function() { + var stock_total = 0; + $('table td .amount-stock-item').each(function(index) { + if ($(this).val() != "") + { + var item_amount = parseFloat($(this).val()); + if ( ! isNaN(item_amount)) + stock_total += item_amount; + } + }); + return stock_total; + } + + /* Add stock item row */ + $('table td .addstockrow').live('click', function() { + var cur_obj = this; + var add_image_url = $(cur_obj).attr('src'); + $(cur_obj).attr('src', <?php echo '\'' . asset_url() . 'images/icons/ajax.gif' . '\''; ?>); + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockvoucher/addstockrow') . '\''; ?>, + success: function(data) { + $(cur_obj).parent().parent().after(data); + $(cur_obj).attr('src', add_image_url); + $('.stock-item-dropdown').trigger('change'); + } + }); + }); + + /* Delete stock item row */ + $('table td .deletestockrow').live('click', function() { + $(this).parent().parent().remove(); + }); + + $('.stock-item-dropdown').trigger('change'); +}); + +</script> + +<?php + echo form_open('inventory/stockvoucher/add/' . $current_voucher_type['label']); + echo "<p>"; + echo "<span id="tooltip-target-1">"; + echo form_label('Voucher Number', 'voucher_number'); + echo " "; + echo $current_voucher_type['prefix'] . form_input($voucher_number) . $current_voucher_type['suffix']; + echo "</span>"; + echo "<span id="tooltip-content-1">Leave Voucher Number empty for auto numbering</span>"; + echo " "; + echo "<span id="tooltip-target-2">"; + echo form_label('Voucher Date', 'voucher_date'); + echo " "; + echo form_input_date_restrict($voucher_date); + echo "</span>"; + echo "<span id="tooltip-content-2">Date format is " . $this->config->item('account_date_format') . ".</span>"; + echo "</p>"; + + echo "<h3>Source</h3>"; + echo "<table class="voucher-table">"; + echo "<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate Per Unit</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + + foreach ($source_stock_item_id as $i => $row) + { + $source_stock_item_quantity_item = array( + 'name' => 'source_stock_item_quantity[' . $i . ']', + 'id' => 'source_stock_item_quantity[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => isset($source_stock_item_quantity[$i]) ? $source_stock_item_quantity[$i] : '', + 'class' => 'source-quantity-stock-item', + ); + $source_stock_item_rate_per_unit_item = array( + 'name' => 'source_stock_item_rate_per_unit[' . $i . ']', + 'id' => 'source_stock_item_rate_per_unit[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => isset($source_stock_item_rate_per_unit[$i]) ? $source_stock_item_rate_per_unit[$i] : '', + 'class' => 'source-rate-stock-item', + ); + $source_stock_item_amount_item = array( + 'name' => 'source_stock_item_amount[' . $i . ']', + 'id' => 'source_stock_item_amount[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => isset($source_stock_item_amount[$i]) ? $source_stock_item_amount[$i] : '', + 'class' => 'source-amount-stock-item', + ); + echo "<tr>"; + + echo "<td>" . form_input_stock_item('source_stock_item_id[' . $i . ']', isset($source_stock_item_id[$i]) ? $source_stock_item_id[$i] : 0) . "</td>"; + echo "<td>" . form_input($source_stock_item_quantity_item) . "</td>"; + echo "<td>" . form_input($source_stock_item_rate_per_unit_item) . "</td>"; + echo "<td>" . form_input($source_stock_item_amount_item) . "</td>"; + + echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addstockrow')) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deletestockrow')) . "</td>"; + + echo "<td class="source-stock-item-balance"><div></div></td>"; + + echo "</tr>"; + } + echo "</table>"; + + echo "<h3>Destination</h3>"; + echo "<table class="voucher-table">"; + echo "<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate Per Unit</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + + foreach ($dest_stock_item_id as $i => $row) + { + $dest_stock_item_quantity_item = array( + 'name' => 'dest_stock_item_quantity[' . $i . ']', + 'id' => 'dest_stock_item_quantity[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => isset($dest_stock_item_quantity[$i]) ? $dest_stock_item_quantity[$i] : '', + 'class' => 'dest-quantity-stock-item', + ); + $dest_stock_item_rate_per_unit_item = array( + 'name' => 'dest_stock_item_rate_per_unit[' . $i . ']', + 'id' => 'dest_stock_item_rate_per_unit[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => isset($dest_stock_item_rate_per_unit[$i]) ? $dest_stock_item_rate_per_unit[$i] : '', + 'class' => 'dest-rate-stock-item', + ); + $dest_stock_item_amount_item = array( + 'name' => 'dest_stock_item_amount[' . $i . ']', + 'id' => 'dest_stock_item_amount[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => isset($dest_stock_item_amount[$i]) ? $dest_stock_item_amount[$i] : '', + 'class' => 'dest-amount-stock-item', + ); + echo "<tr>"; + + echo "<td>" . form_input_stock_item('dest_stock_item_id[' . $i . ']', isset($dest_stock_item_id[$i]) ? $dest_stock_item_id[$i] : 0) . "</td>"; + echo "<td>" . form_input($dest_stock_item_quantity_item) . "</td>"; + echo "<td>" . form_input($dest_stock_item_rate_per_unit_item) . "</td>"; + echo "<td>" . form_input($dest_stock_item_amount_item) . "</td>"; + + echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addstockrow')) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deletestockrow')) . "</td>"; + + echo "<td class="dest-stock-item-balance"><div></div></td>"; + + echo "</tr>"; + } + echo "</table>"; + + echo "<br />"; + echo "<br />"; + + echo "<p>"; + echo form_label('Narration', 'voucher_narration'); + echo "<br />"; + echo form_textarea($voucher_narration); + echo "</p>"; + + echo "<p>"; + echo form_label('Tag', 'voucher_tag'); + echo " "; + echo form_dropdown('voucher_tag', $voucher_tags, $voucher_tag); + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Create'); + echo " "; + echo anchor('voucher/show/' . $current_voucher_type['label'], 'Back', array('title' => 'Back to ' . $current_voucher_type['name'] . ' Vouchers')); + echo "</p>"; + + echo form_close(); +
commit 2b8a1f44400c7bee9b4ac8d3d705d6666e91e7b8 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Mon Feb 28 23:02:34 2011 +0530
Added basic links for stock transfer
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stocktransfer.php b/system/application/controllers/inventory/stocktransfer.php new file mode 100644 index 0000000..1dec9bd --- /dev/null +++ b/system/application/controllers/inventory/stocktransfer.php @@ -0,0 +1,1549 @@ +<?php + +class StockTransfer extends Controller { + + function StockTransfer() + { + parent::Controller(); + $this->load->model('Voucher_model'); + $this->load->model('Ledger_model'); + $this->load->model('Stock_Item_model'); + $this->load->model('Tag_model'); + return; + } + + function index() + { + redirect('voucher/show/all'); + return; + } + + function view($voucher_type, $voucher_id = 0) + { + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + if ($current_voucher_type['base_type'] == '1') + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } + + $this->template->set('page_title', 'View ' . $current_voucher_type['name'] . ' Voucher'); + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + /* Load current voucher details - account, entity, ledgers */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); + $cur_voucher_main_account = $this->db->get(); + if ($cur_voucher_main_account->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); + $cur_voucher_main_entity = $this->db->get(); + if ($cur_voucher_main_entity->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); + $cur_voucher_ledgers = $this->db->get(); + if ($cur_voucher_ledgers->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); + } + + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); + $cur_voucher_stock_items = $this->db->get(); + if ($cur_voucher_stock_items->num_rows() < 1) + { + $this->messages->add('Voucher has no associated stock items.', 'error'); + } + + $data['cur_voucher'] = $cur_voucher; + $data['cur_voucher_main_account'] = $cur_voucher_main_account; + $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; + $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; + $data['cur_voucher_stock_items'] = $cur_voucher_stock_items; + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + $this->template->load('template', 'inventory/stockvoucher/view', $data); + return; + } + + function add($voucher_type) + { + /* Check access */ + if ( ! check_access('create stock voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('voucher/show/' . $voucher_type); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + if ($current_voucher_type['stock_voucher_type'] != '3') + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } + + $this->template->set('page_title', 'New ' . $current_voucher_type['name'] . ' Voucher'); + + /* Form fields */ + $data['voucher_number'] = array( + 'name' => 'voucher_number', + 'id' => 'voucher_number', + 'maxlength' => '11', + 'size' => '11', + 'value' => '', + ); + $data['voucher_date'] = array( + 'name' => 'voucher_date', + 'id' => 'voucher_date', + 'maxlength' => '11', + 'size' => '11', + 'value' => date_today_php(), + ); + $data['voucher_narration'] = array( + 'name' => 'voucher_narration', + 'id' => 'voucher_narration', + 'cols' => '50', + 'rows' => '4', + 'value' => '', + ); + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + $data['voucher_tags'] = $this->Tag_model->get_all_tags(); + $data['voucher_tag'] = 0; + + /* Form validations */ + if ($current_voucher_type['numbering'] == '2') + $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|required|is_natural_no_zero|uniquevoucherno[' . $voucher_type_id . ']'); + else if ($current_voucher_type['numbering'] == '3') + $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|is_natural_no_zero|uniquevoucherno[' . $voucher_type_id . ']'); + else + $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|is_natural_no_zero|uniquevoucherno[' . $voucher_type_id . ']'); + $this->form_validation->set_rules('voucher_date', 'Voucher Date', 'trim|required|is_date|is_date_within_range'); + if ($current_voucher_type['stock_voucher_type'] == '3') + { + + } + $this->form_validation->set_rules('voucher_narration', 'trim'); + $this->form_validation->set_rules('voucher_tag', 'Tag', 'trim|is_natural'); + + /* Debit and Credit amount validation */ + if ($_POST) + { + foreach ($this->input->post('stock_item_id', TRUE) as $id => $stock_data) + { + $this->form_validation->set_rules('stock_item_quantity[' . $id . ']', 'Stock Item Quantity', 'trim|quantity'); + $this->form_validation->set_rules('stock_item_rate_per_unit[' . $id . ']', 'Stock Item Rate Per Unit', 'trim|currency'); + $this->form_validation->set_rules('stock_item_discount[' . $id . ']', 'Stock Item Discount', 'trim|discount'); + $this->form_validation->set_rules('stock_item_amount[' . $id . ']', 'Stock Item Amount', 'trim|currency'); + } + foreach ($this->input->post('ledger_dc', TRUE) as $id => $ledger_data) + { + $this->form_validation->set_rules('rate_item[' . $id . ']', 'Rate %', 'trim|rate'); + $this->form_validation->set_rules('amount_item[' . $id . ']', 'Ledger Amount', 'trim|currency'); + } + } + + /* Repopulating form */ + if ($_POST) + { + $data['voucher_number']['value'] = $this->input->post('voucher_number', TRUE); + $data['voucher_date']['value'] = $this->input->post('voucher_date', TRUE); + $data['voucher_narration']['value'] = $this->input->post('voucher_narration', TRUE); + $data['voucher_tag'] = $this->input->post('voucher_tag', TRUE); + + $data['main_account_active'] = $this->input->post('main_account', TRUE); + $data['main_entity_active'] = $this->input->post('main_entity', TRUE); + + $data['stock_item_id'] = $this->input->post('stock_item_id', TRUE); + $data['stock_item_quantity'] = $this->input->post('stock_item_quantity', TRUE); + $data['stock_item_rate_per_unit'] = $this->input->post('stock_item_rate_per_unit', TRUE); + $data['stock_item_discount'] = $this->input->post('stock_item_discount', TRUE); + $data['stock_item_amount'] = $this->input->post('stock_item_amount', TRUE); + + $data['ledger_dc'] = $this->input->post('ledger_dc', TRUE); + $data['ledger_id'] = $this->input->post('ledger_id', TRUE); + $data['rate_item'] = $this->input->post('rate_item', TRUE); + $data['amount_item'] = $this->input->post('amount_item', TRUE); + } else { + for ($count = 0; $count <= 3; $count++) + { + $data['stock_item_id'][$count] = '0'; + $data['stock_item_quantity'][$count] = ''; + $data['stock_item_rate_per_unit'][$count] = ''; + $data['stock_item_discount'][$count] = ''; + $data['stock_item_amount'][$count] = ''; + } + for ($count = 0; $count <= 1; $count++) + { + $data['ledger_dc'][$count] = "D"; + $data['ledger_id'][$count] = 0; + $data['rate_item'][$count] = ""; + $data['amount_item'][$count] = ""; + } + } + + if ($this->form_validation->run() == FALSE) + { + $this->messages->add(validation_errors(), 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + else + { + $data_main_account = $this->input->post('main_account', TRUE); + $data_main_entity = $this->input->post('main_entity', TRUE); + + $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); + $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); + $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); + $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); + $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); + + $data_all_ledger_id = $this->input->post('ledger_id', TRUE); + $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); + $data_all_rate_item = $this->input->post('rate_item', TRUE); + $data_all_amount_item = $this->input->post('amount_item', TRUE); + + $data_total_amount = 0; + + /* Setting Stock Item type */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $data_stock_item_type = 1; + else + $data_stock_item_type = 2; + + /* Checking for Valid Stock Ledger A/C - account */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 2); + else + $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 3); + $valid_main_account_q = $this->db->get(); + if ($valid_main_account_q->num_rows() < 1) + { + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->messages->add('Invalid Purchase Ledger A/C.', 'error'); + else + $this->messages->add('Invalid Sale Ledger A/C.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + /* Checking for Valid Stock Ledger A/C - entity */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 4)->or_where('type', 1); + else + $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 5)->or_where('type', 1); + $valid_main_account_q = $this->db->get(); + if ($valid_main_account_q->num_rows() < 1) + { + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->messages->add('Invalid Creditor (Supplier).', 'error'); + else + $this->messages->add('Invalid Debtor (Customer).', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + + /* Checking for Valid Stock Item A/C */ + $stock_item_present = FALSE; + $data_total_stock_amount = 0; + foreach ($data_all_stock_item_id as $id => $stock_data) + { + if ($data_all_stock_item_id[$id] < 1) + continue; + + /* Check for valid stock item id */ + $this->db->from('stock_items')->where('id', $data_all_stock_item_id[$id]); + $valid_stock_item_q = $this->db->get(); + if ($valid_stock_item_q->num_rows() < 1) + { + $this->messages->add('Invalid Stock Item.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + $stock_item_present = TRUE; + $data_total_stock_amount += $data_all_stock_item_amount[$id]; + } + if ( ! $stock_item_present) + { + $this->messages->add('No Stock Item selected.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + + /* Checking for Valid Ledgers A/C */ + $data_total_ledger_amount = 0; + foreach ($data_all_ledger_dc as $id => $ledger_data) + { + if ($data_all_ledger_id[$id] < 1) + continue; + + /* Check for valid ledger id */ + $this->db->from('ledgers')->where('id', $data_all_ledger_id[$id]); + $valid_ledger_q = $this->db->get(); + if ($valid_ledger_q->num_rows() < 1) + { + $this->messages->add('Invalid Ledger A/C.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + if ($data_all_ledger_dc[$id] == 'D') + $data_total_ledger_amount += $data_all_amount_item[$id]; + else + $data_total_ledger_amount -= $data_all_amount_item[$id]; + } + + /* Total amount calculations */ + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $data_main_account_total = $data_total_stock_amount; + $data_main_entity_total = $data_total_stock_amount + $data_total_ledger_amount; + } else { + $data_main_account_total = $data_total_stock_amount + $data_total_ledger_amount; + $data_main_entity_total = $data_total_stock_amount; + } + $data_total_amount = $data_total_stock_amount + $data_total_ledger_amount; + if ($data_total_amount < 0) + { + $this->messages->add($current_voucher_type['name'] . ' Voucher total cannot be negative.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + + /* Adding main voucher */ + if ($current_voucher_type['numbering'] == '2') + { + $data_number = $this->input->post('voucher_number', TRUE); + } else if ($current_voucher_type['numbering'] == '3') { + $data_number = $this->input->post('voucher_number', TRUE); + if ( ! $data_number) + $data_number = NULL; + } else { + if ($this->input->post('voucher_number', TRUE)) + $data_number = $this->input->post('voucher_number', TRUE); + else + $data_number = $this->Voucher_model->next_voucher_number($voucher_type_id); + } + + $data_date = $this->input->post('voucher_date', TRUE); + $data_narration = $this->input->post('voucher_narration', TRUE); + $data_tag = $this->input->post('voucher_tag', TRUE); + if ($data_tag < 1) + $data_tag = NULL; + $data_type = $voucher_type_id; + $data_date = date_php_to_mysql($data_date); // Converting date to MySQL + $voucher_id = NULL; + + /* Adding Voucher */ + $this->db->trans_start(); + $insert_data = array( + 'number' => $data_number, + 'date' => $data_date, + 'narration' => $data_narration, + 'voucher_type' => $data_type, + 'tag_id' => $data_tag, + ); + if ( ! $this->db->insert('vouchers', $insert_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error addding Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting voucher"); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } else { + $voucher_id = $this->db->insert_id(); + } + + /* Adding main - account */ + $insert_data = array( + 'voucher_id' => $voucher_id, + 'ledger_id' => $data_main_account, + 'amount' => $data_main_account_total, + 'dc' => '', + 'reconciliation_date' => NULL, + 'stock_type' => 1, + 'stock_rate' => '', + ); + if ($current_voucher_type['stock_voucher_type'] == '1') + $insert_data['dc'] = 'D'; + else + $insert_data['dc'] = 'C'; + if ( ! $this->db->insert('voucher_items', $insert_data)) + { + $this->db->trans_rollback(); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->messages->add('Error adding Purchase Ledger A/C to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting purchase ledger " . "[id:" . $data_main_account . "]"); + } else { + $this->messages->add('Error adding Sale Ledger A/C to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting sale ledger " . "[id:" . $data_main_account . "]"); + } + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } else { + $main_voucher_id = $this->db->insert_id(); + } + + /* Adding main - entity */ + $insert_data = array( + 'voucher_id' => $voucher_id, + 'ledger_id' => $data_main_entity, + 'amount' => $data_main_entity_total, + 'dc' => '', + 'reconciliation_date' => NULL, + 'stock_type' => 2, + 'stock_rate' => '', + ); + if ($current_voucher_type['stock_voucher_type'] == '1') + $insert_data['dc'] = 'C'; + else + $insert_data['dc'] = 'D'; + if ( ! $this->db->insert('voucher_items', $insert_data)) + { + $this->db->trans_rollback(); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->messages->add('Error adding Creditor (Supplier) to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting creditor ledger " . "[id:" . $data_main_entity . "]"); + } else { + $this->messages->add('Error adding Debtor (Customer) - to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting debtor ledger " . "[id:" . $data_main_entity . "]"); + } + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } else { + $entity_voucher_id = $this->db->insert_id(); + } + + /* Adding stock items */ + $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); + $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); + $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); + $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); + $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); + + foreach ($data_all_stock_item_id as $id => $stock_data) + { + $data_stock_item_id = $data_all_stock_item_id[$id]; + + if ($data_stock_item_id < 1) + continue; + + $data_stock_item_quantity = $data_all_stock_item_quantity[$id]; + $data_stock_item_rate_per_unit = $data_all_stock_item_rate_per_unit[$id]; + $data_stock_item_discount = $data_all_stock_item_discount[$id]; + $data_stock_item_amount = $data_all_stock_item_amount[$id]; + + $insert_stock_data = array( + 'voucher_id' => $voucher_id, + 'stock_item_id' => $data_stock_item_id, + 'quantity' => $data_stock_item_quantity, + 'rate_per_unit' => $data_stock_item_rate_per_unit, + 'discount' => $data_stock_item_discount, + 'total' => $data_stock_item_amount, + 'type' => $data_stock_item_type, + ); + if ( ! $this->db->insert('stock_voucher_items', $insert_stock_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error adding Stock Item - ' . $data_ledger_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_ledger_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + } + + /* Adding ledger accounts */ + $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); + $data_all_ledger_id = $this->input->post('ledger_id', TRUE); + $data_all_rate_item = $this->input->post('rate_item', TRUE); + $data_all_amount_item = $this->input->post('amount_item', TRUE); + + foreach ($data_all_ledger_dc as $id => $ledger_data) + { + $data_ledger_dc = $data_all_ledger_dc[$id]; + $data_ledger_id = $data_all_ledger_id[$id]; + + if ($data_ledger_id < 1) + continue; + + $data_rate = $data_all_rate_item[$id]; + $data_amount = $data_all_amount_item[$id]; + + $insert_ledger_data = array( + 'voucher_id' => $voucher_id, + 'ledger_id' => $data_ledger_id, + 'amount' => $data_amount, + 'dc' => $data_ledger_dc, + 'reconciliation_date' => NULL, + 'stock_type' => 3, + 'stock_rate' => $data_rate, + ); + if ( ! $this->db->insert('voucher_items', $insert_ledger_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error adding Ledger A/C - ' . $data_ledger_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting voucher ledger item " . "[id:" . $data_ledger_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + } + + /* Updating Debit and Credit Total - vouchers */ + $update_data = array( + 'dr_total' => $data_total_amount, + 'cr_total' => $data_total_amount, + ); + + if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error updating Voucher total.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debit and credit total"); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + + /* Success */ + $this->db->trans_complete(); + + $this->session->set_userdata('voucher_added_show_action', TRUE); + $this->session->set_userdata('voucher_added_id', $voucher_id); + $this->session->set_userdata('voucher_added_type_id', $voucher_type_id); + $this->session->set_userdata('voucher_added_type_label', $current_voucher_type['label']); + $this->session->set_userdata('voucher_added_type_name', $current_voucher_type['name']); + $this->session->set_userdata('voucher_added_type_base_type', $current_voucher_type['base_type']); + $this->session->set_userdata('voucher_added_number', $data_number); + + /* Showing success message in show() method since message is too long for storing it in session */ + $this->logger->write_message("success", "Added " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + redirect('voucher/show/' . $current_voucher_type['label']); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + return; + } + + function edit($voucher_type, $voucher_id = 0) + { + /* Check access */ + if ( ! check_access('edit stock voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('voucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + $this->template->set('page_title', 'Edit ' . $current_voucher_type['name'] . ' Voucher'); + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + /* Form fields - Voucher */ + $data['voucher_number'] = array( + 'name' => 'voucher_number', + 'id' => 'voucher_number', + 'maxlength' => '11', + 'size' => '11', + 'value' => $cur_voucher->number, + ); + $data['voucher_date'] = array( + 'name' => 'voucher_date', + 'id' => 'voucher_date', + 'maxlength' => '11', + 'size' => '11', + 'value' => date_mysql_to_php($cur_voucher->date), + ); + $data['voucher_narration'] = array( + 'name' => 'voucher_narration', + 'id' => 'voucher_narration', + 'cols' => '50', + 'rows' => '4', + 'value' => $cur_voucher->narration, + ); + $data['voucher_id'] = $voucher_id; + $data['main_account_active'] = 0; + $data['main_entity_active'] = 0; + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + $data['voucher_tag'] = $cur_voucher->tag_id; + $data['voucher_tags'] = $this->Tag_model->get_all_tags(); + $data['has_reconciliation'] = FALSE; + + /* Load current ledger details if not $_POST */ + if ( ! $_POST) + { + /* main - account */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1); + $cur_main_account_q = $this->db->get(); + $cur_main_account = $cur_main_account_q->row(); + $data['main_account_active'] = $cur_main_account->ledger_id; + + /* main - entity */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2); + $cur_main_entity_q = $this->db->get(); + $cur_main_entity = $cur_main_entity_q->row(); + $data['main_entity_active'] = $cur_main_entity->ledger_id; + + /* ledgers */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3); + $cur_ledgers_q = $this->db->get(); + $counter = 0; + foreach ($cur_ledgers_q->result() as $row) + { + $data['ledger_dc'][$counter] = $row->dc; + $data['ledger_id'][$counter] = $row->ledger_id; + $data['rate_item'][$counter] = $row->stock_rate; + $data['amount_item'][$counter] = $row->amount; + if ($row->reconciliation_date) + $data['has_reconciliation'] = TRUE; + $counter++; + } + /* one extra rows */ + $data['ledger_dc'][$counter] = 'D'; + $data['ledger_id'][$counter] = 0; + $data['rate_item'][$counter] = ""; + $data['amount_item'][$counter] = ""; + $counter++; + + /* stock items */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id); + $cur_stock_item_q = $this->db->get(); + $counter = 0; + foreach ($cur_stock_item_q->result() as $row) + { + $data['stock_item_id'][$counter] = $row->stock_item_id; + $data['stock_item_quantity'][$counter] = $row->quantity; + $data['stock_item_rate_per_unit'][$counter] = $row->rate_per_unit; + $data['stock_item_discount'][$counter] = $row->discount; + $data['stock_item_amount'][$counter] = $row->total; + $counter++; + } + /* one extra rows */ + $data['stock_item_id'][$counter] = '0'; + $data['stock_item_quantity'][$counter] = ""; + $data['stock_item_rate_per_unit'][$counter] = ""; + $data['stock_item_discount'][$counter] = ""; + $data['stock_item_amount'][$counter] = ""; + $counter++; + } + + /* Form validations */ + if ($current_voucher_type['numbering'] == '3') + $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|is_natural_no_zero|uniquevouchernowithid[' . $voucher_type_id . '.' . $voucher_id . ']'); + else + $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|required|is_natural_no_zero|uniquevouchernowithid[' . $voucher_type_id . '.' . $voucher_id . ']'); + $this->form_validation->set_rules('voucher_date', 'Voucher Date', 'trim|required|is_date|is_date_within_range'); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->form_validation->set_rules('main_account', 'Purchase Ledger A/C', 'trim|required'); + $this->form_validation->set_rules('main_entity', 'Creditors (Supplier)', 'trim|required'); + } else { + $this->form_validation->set_rules('main_account', 'Sale Ledger A/C', 'trim|required'); + $this->form_validation->set_rules('main_entity', 'Debtor (Customer)', 'trim|required'); + } + $this->form_validation->set_rules('voucher_narration', 'trim'); + $this->form_validation->set_rules('voucher_tag', 'Tag', 'trim|is_natural'); + + /* Debit and Credit amount validation */ + if ($_POST) + { + foreach ($this->input->post('stock_item_id', TRUE) as $id => $stock_data) + { + $this->form_validation->set_rules('stock_item_quantity[' . $id . ']', 'Stock Item Quantity', 'trim|quantity'); + $this->form_validation->set_rules('stock_item_rate_per_unit[' . $id . ']', 'Stock Item Rate Per Unit', 'trim|currency'); + $this->form_validation->set_rules('stock_item_discount[' . $id . ']', 'Stock Item Discount', 'trim|discount'); + $this->form_validation->set_rules('stock_item_amount[' . $id . ']', 'Stock Item Amount', 'trim|currency'); + } + foreach ($this->input->post('ledger_dc', TRUE) as $id => $ledger_data) + { + $this->form_validation->set_rules('rate_item[' . $id . ']', 'Rate %', 'trim|rate'); + $this->form_validation->set_rules('amount_item[' . $id . ']', 'Ledger Amount', 'trim|currency'); + } + } + + /* Repopulating form */ + if ($_POST) + { + $data['voucher_number']['value'] = $this->input->post('voucher_number', TRUE); + $data['voucher_date']['value'] = $this->input->post('voucher_date', TRUE); + $data['voucher_narration']['value'] = $this->input->post('voucher_narration', TRUE); + $data['voucher_tag'] = $this->input->post('voucher_tag', TRUE); + $data['has_reconciliation'] = $this->input->post('has_reconciliation', TRUE); + + $data['main_account_active'] = $this->input->post('main_account', TRUE); + $data['main_entity_active'] = $this->input->post('main_entity', TRUE); + + $data['stock_item_id'] = $this->input->post('stock_item_id', TRUE); + $data['stock_item_quantity'] = $this->input->post('stock_item_quantity', TRUE); + $data['stock_item_rate_per_unit'] = $this->input->post('stock_item_rate_per_unit', TRUE); + $data['stock_item_discount'] = $this->input->post('stock_item_discount', TRUE); + $data['stock_item_amount'] = $this->input->post('stock_item_amount', TRUE); + + $data['ledger_dc'] = $this->input->post('ledger_dc', TRUE); + $data['ledger_id'] = $this->input->post('ledger_id', TRUE); + $data['rate_item'] = $this->input->post('rate_item', TRUE); + $data['amount_item'] = $this->input->post('amount_item', TRUE); + } + + if ($this->form_validation->run() == FALSE) + { + $this->messages->add(validation_errors(), 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + } else { + $data_main_account = $this->input->post('main_account', TRUE); + $data_main_entity = $this->input->post('main_entity', TRUE); + + $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); + $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); + $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); + $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); + $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); + + $data_all_ledger_id = $this->input->post('ledger_id', TRUE); + $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); + $data_all_rate_item = $this->input->post('rate_item', TRUE); + $data_all_amount_item = $this->input->post('amount_item', TRUE); + + $data_total_amount = 0; + + /* Setting Stock Item type */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $data_stock_item_type = 1; + else + $data_stock_item_type = 2; + + /* Checking for Valid Stock Ledger A/C - account */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 2); + else + $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 3); + $valid_main_account_q = $this->db->get(); + if ($valid_main_account_q->num_rows() < 1) + { + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->messages->add('Invalid Purchase Ledger A/C.', 'error'); + else + $this->messages->add('Invalid Sale Ledger A/C.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + /* Checking for Valid Stock Ledger A/C - entity */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 4)->or_where('type', 1); + else + $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 5)->or_where('type', 1); + $valid_main_account_q = $this->db->get(); + if ($valid_main_account_q->num_rows() < 1) + { + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->messages->add('Invalid Creditor (Supplier).', 'error'); + else + $this->messages->add('Invalid Debtor (Customer).', 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* Checking for Valid Stock Item A/C */ + $stock_item_present = FALSE; + $data_total_stock_amount = 0; + foreach ($data_all_stock_item_id as $id => $stock_data) + { + if ($data_all_stock_item_id[$id] < 1) + continue; + + /* Check for valid stock item id */ + $this->db->from('stock_items')->where('id', $data_all_stock_item_id[$id]); + $valid_stock_item_q = $this->db->get(); + if ($valid_stock_item_q->num_rows() < 1) + { + $this->messages->add('Invalid Stock Item.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + $stock_item_present = TRUE; + $data_total_stock_amount += $data_all_stock_item_amount[$id]; + } + if ( ! $stock_item_present) + { + $this->messages->add('No Stock Item selected.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* Checking for Valid Ledgers A/C */ + $data_total_ledger_amount = 0; + foreach ($data_all_ledger_dc as $id => $ledger_data) + { + if ($data_all_ledger_id[$id] < 1) + continue; + + /* Check for valid ledger id */ + $this->db->from('ledgers')->where('id', $data_all_ledger_id[$id]); + $valid_ledger_q = $this->db->get(); + if ($valid_ledger_q->num_rows() < 1) + { + $this->messages->add('Invalid Ledger A/C.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + if ($data_all_ledger_dc[$id] == 'D') + $data_total_ledger_amount += $data_all_amount_item[$id]; + else + $data_total_ledger_amount -= $data_all_amount_item[$id]; + } + + /* Total amount calculations */ + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $data_main_account_total = $data_total_stock_amount; + $data_main_entity_total = $data_total_stock_amount + $data_total_ledger_amount; + } else { + $data_main_account_total = $data_total_stock_amount + $data_total_ledger_amount; + $data_main_entity_total = $data_total_stock_amount; + } + $data_total_amount = $data_total_stock_amount + $data_total_ledger_amount; + if ($data_total_amount < 0) + { + $this->messages->add($current_voucher_type['name'] . ' Voucher total cannot be negative.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* Updating main voucher */ + if ($current_voucher_type['numbering'] == '3') { + $data_number = $this->input->post('voucher_number', TRUE); + if ( ! $data_number) + $data_number = NULL; + } else { + $data_number = $this->input->post('voucher_number', TRUE); + } + + $data_date = $this->input->post('voucher_date', TRUE); + $data_narration = $this->input->post('voucher_narration', TRUE); + $data_tag = $this->input->post('voucher_tag', TRUE); + if ($data_tag < 1) + $data_tag = NULL; + $data_type = $voucher_type_id; + $data_date = date_php_to_mysql($data_date); // Converting date to MySQL + $data_has_reconciliation = $this->input->post('has_reconciliation', TRUE); + + $this->db->trans_start(); + $update_data = array( + 'number' => $data_number, + 'date' => $data_date, + 'narration' => $data_narration, + 'tag_id' => $data_tag, + ); + if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error updating Voucher A/C.', 'error'); + $this->logger->write_message("error", "Error updating voucher details for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* TODO : Deleting all old ledger data, Bad solution */ + if ( ! $this->db->delete('stock_voucher_items', array('voucher_id' => $voucher_id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting previous stock items from Voucher.', 'error'); + $this->logger->write_message("error", "Error deleting previous stock items from " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + if ( ! $this->db->delete('voucher_items', array('voucher_id' => $voucher_id))->where('stock_type', 3)) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting previous Ledger A/C's from Voucher.', 'error'); + $this->logger->write_message("error", "Error deleting previous voucher items for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* Updating main - account */ + $update_data = array( + 'ledger_id' => $data_main_account, + 'amount' => $data_main_account_total, + 'dc' => '', + 'reconciliation_date' => NULL, + 'stock_type' => 1, + 'stock_rate' => '', + ); + if ($current_voucher_type['stock_voucher_type'] == '1') + $update_data['dc'] = 'D'; + else + $update_data['dc'] = 'C'; + if ( ! $this->db->where('voucher_id', $voucher_id)->where('stock_type', 1)->update('voucher_items', $update_data)) + { + $this->db->trans_rollback(); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->messages->add('Error updating Purchase Ledger A/C of Voucher.', 'error'); + $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating purchase ledger " . "[id:" . $data_main_account . "]"); + } else { + $this->messages->add('Error updating Sale Ledger A/C of Voucher.', 'error'); + $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating sale ledger " . "[id:" . $data_main_account . "]"); + } + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* Updating main - entity */ + $update_data = array( + 'ledger_id' => $data_main_entity, + 'amount' => $data_main_entity_total, + 'dc' => '', + 'reconciliation_date' => NULL, + 'stock_type' => 2, + 'stock_rate' => '', + ); + if ($current_voucher_type['stock_voucher_type'] == '1') + $insert_data['dc'] = 'C'; + else + $insert_data['dc'] = 'D'; + if ( ! $this->db->where('voucher_id', $voucher_id)->where('stock_type', 2)->update('voucher_items', $update_data)) + { + $this->db->trans_rollback(); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->messages->add('Error updating Creditor (Supplier) of Voucher.', 'error'); + $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating creditor ledger " . "[id:" . $data_main_entity . "]"); + } else { + $this->messages->add('Error updating Debtor (Customer) of Voucher.', 'error'); + $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debtor ledger " . "[id:" . $data_main_entity . "]"); + } + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* Adding stock items */ + $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); + $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); + $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); + $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); + $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); + + foreach ($data_all_stock_item_id as $id => $stock_data) + { + $data_stock_item_id = $data_all_stock_item_id[$id]; + + if ($data_stock_item_id < 1) + continue; + + $data_stock_item_quantity = $data_all_stock_item_quantity[$id]; + $data_stock_item_rate_per_unit = $data_all_stock_item_rate_per_unit[$id]; + $data_stock_item_discount = $data_all_stock_item_discount[$id]; + $data_stock_item_amount = $data_all_stock_item_amount[$id]; + + $insert_stock_data = array( + 'voucher_id' => $voucher_id, + 'stock_item_id' => $data_stock_item_id, + 'quantity' => $data_stock_item_quantity, + 'rate_per_unit' => $data_stock_item_rate_per_unit, + 'discount' => $data_stock_item_discount, + 'total' => $data_stock_item_amount, + 'type' => $data_stock_item_type, + ); + if ( ! $this->db->insert('stock_voucher_items', $insert_stock_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error adding Stock Item - ' . $data_ledger_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_ledger_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + } + + /* Adding ledger accounts */ + $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); + $data_all_ledger_id = $this->input->post('ledger_id', TRUE); + $data_all_rate_item = $this->input->post('rate_item', TRUE); + $data_all_amount_item = $this->input->post('amount_item', TRUE); + + foreach ($data_all_ledger_dc as $id => $ledger_data) + { + $data_ledger_dc = $data_all_ledger_dc[$id]; + $data_ledger_id = $data_all_ledger_id[$id]; + + if ($data_ledger_id < 1) + continue; + + $data_rate = $data_all_rate_item[$id]; + $data_amount = $data_all_amount_item[$id]; + + $insert_ledger_data = array( + 'voucher_id' => $voucher_id, + 'ledger_id' => $data_ledger_id, + 'amount' => $data_amount, + 'dc' => $data_ledger_dc, + 'reconciliation_date' => NULL, + 'stock_type' => 3, + 'stock_rate' => $data_rate, + ); + if ( ! $this->db->insert('voucher_items', $insert_ledger_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error adding Ledger A/C - ' . $data_ledger_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting voucher ledger item " . "[id:" . $data_ledger_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + } + + /* Updating Debit and Credit Total - vouchers */ + $update_data = array( + 'dr_total' => $data_total_amount, + 'cr_total' => $data_total_amount, + ); + + if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error updating Voucher total.', 'error'); + $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debit and credit total"); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* Success */ + $this->db->trans_complete(); + + $this->session->set_userdata('voucher_updated_show_action', TRUE); + $this->session->set_userdata('voucher_updated_id', $voucher_id); + $this->session->set_userdata('voucher_updated_type_id', $voucher_type_id); + $this->session->set_userdata('voucher_updated_type_label', $current_voucher_type['label']); + $this->session->set_userdata('voucher_updated_type_name', $current_voucher_type['name']); + $this->session->set_userdata('voucher_updated_number', $data_number); + if ($data_has_reconciliation) + $this->session->set_userdata('voucher_updated_has_reconciliation', TRUE); + else + $this->session->set_userdata('voucher_updated_has_reconciliation', FALSE); + + /* Showing success message in show() method since message is too long for storing it in session */ + $this->logger->write_message("success", "Updated " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + return; + } + + function delete($voucher_type, $voucher_id = 0) + { + /* Check access */ + if ( ! check_access('delete stock voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('voucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + $this->db->trans_start(); + if ( ! $this->db->delete('stock_voucher_items', array('voucher_id' => $voucher_id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting Stock Items.', 'error'); + $this->logger->write_message("error", "Error deleting stock item entries for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + redirect('voucher/view/' . $current_voucher_type['label'] . '/' . $voucher_id); + return; + } + if ( ! $this->db->delete('voucher_items', array('voucher_id' => $voucher_id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting Voucher - Ledger A/C's.', 'error'); + $this->logger->write_message("error", "Error deleting ledger entries for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + redirect('voucher/view/' . $current_voucher_type['label'] . '/' . $voucher_id); + return; + } + if ( ! $this->db->delete('vouchers', array('id' => $voucher_id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting Voucher entry.', 'error'); + $this->logger->write_message("error", "Error deleting Voucher entry for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + redirect('voucher/view/' . $current_voucher_type['label'] . '/' . $voucher_id); + return; + } + $this->db->trans_complete(); + $this->messages->add('Deleted ' . $current_voucher_type['name'] . ' Voucher.', 'success'); + $this->logger->write_message("success", "Deleted " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + function download($voucher_type, $voucher_id = 0) + { + $this->load->helper('download'); + $this->load->model('Setting_model'); + + /* Check access */ + if ( ! check_access('download stock voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + if ($current_voucher_type['base_type'] == '1') + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + /* Load current voucher details - account, entity, ledgers */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); + $cur_voucher_main_account = $this->db->get(); + if ($cur_voucher_main_account->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); + $cur_voucher_main_entity = $this->db->get(); + if ($cur_voucher_main_entity->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); + $cur_voucher_ledgers = $this->db->get(); + if ($cur_voucher_ledgers->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); + } + + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); + $cur_voucher_stock_items = $this->db->get(); + if ($cur_voucher_stock_items->num_rows() < 1) + { + $this->messages->add('Voucher has no associated stock items.', 'error'); + } + + $data['cur_voucher'] = $cur_voucher; + $data['cur_voucher_main_account'] = $cur_voucher_main_account; + $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; + $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; + $data['cur_voucher_stock_items'] = $cur_voucher_stock_items; + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + + /* Download Voucher */ + $file_name = $current_voucher_type['name'] . '_voucher_' . $cur_voucher->number . ".html"; + $download_data = $this->load->view('inventory/stockvoucher/downloadpreview', $data, TRUE); + force_download($file_name, $download_data); + return; + } + + function printpreview($voucher_type, $voucher_id = 0) + { + $this->load->model('Setting_model'); + + /* Check access */ + if ( ! check_access('print stock voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + if ($current_voucher_type['base_type'] == '1') + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + /* Load current voucher details - account, entity, ledgers */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); + $cur_voucher_main_account = $this->db->get(); + if ($cur_voucher_main_account->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); + $cur_voucher_main_entity = $this->db->get(); + if ($cur_voucher_main_entity->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); + $cur_voucher_ledgers = $this->db->get(); + if ($cur_voucher_ledgers->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); + } + + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); + $cur_voucher_stock_items = $this->db->get(); + if ($cur_voucher_stock_items->num_rows() < 1) + { + $this->messages->add('Voucher has no associated stock items.', 'error'); + } + + $data['cur_voucher'] = $cur_voucher; + $data['cur_voucher_main_account'] = $cur_voucher_main_account; + $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; + $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; + $data['cur_voucher_stock_items'] = $cur_voucher_stock_items; + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + + $this->load->view('inventory/stockvoucher/printpreview', $data); + return; + } + + function email($voucher_type, $voucher_id = 0) + { + $this->load->model('Setting_model'); + $this->load->library('email'); + + /* Check access */ + if ( ! check_access('email stock voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + $account_data = $this->Setting_model->get_current(); + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + /* Load current voucher details - account, entity, ledgers */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); + $cur_voucher_main_account = $this->db->get(); + if ($cur_voucher_main_account->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); + $cur_voucher_main_entity = $this->db->get(); + if ($cur_voucher_main_entity->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); + $cur_voucher_ledgers = $this->db->get(); + if ($cur_voucher_ledgers->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); + } + + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); + $cur_voucher_stock_items = $this->db->get(); + if ($cur_voucher_stock_items->num_rows() < 1) + { + $this->messages->add('Voucher has no associated stock items.', 'error'); + } + + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + $data['voucher_id'] = $voucher_id; + $data['voucher_number'] = $cur_voucher->number; + $data['email_to'] = array( + 'name' => 'email_to', + 'id' => 'email_to', + 'size' => '40', + 'value' => '', + ); + + /* Form validations */ + $this->form_validation->set_rules('email_to', 'Email to', 'trim|valid_emails|required'); + + /* Repopulating form */ + if ($_POST) + { + $data['email_to']['value'] = $this->input->post('email_to', TRUE); + } + + if ($this->form_validation->run() == FALSE) + { + $data['error'] = validation_errors(); + $this->load->view('inventory/stockvoucher/email', $data); + return; + } + else + { + $data['cur_voucher'] = $cur_voucher; + $data['cur_voucher_main_account'] = $cur_voucher_main_account; + $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; + $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; + $data['cur_voucher_stock_items'] = $cur_voucher_stock_items; + + /* Preparing message */ + $message = $this->load->view('inventory/stockvoucher/emailpreview', $data, TRUE); + + /* Getting email configuration */ + $config['smtp_timeout'] = '30'; + $config['charset'] = 'utf-8'; + $config['newline'] = "\r\n"; + $config['mailtype'] = "html"; + if ($account_data) + { + $config['protocol'] = $account_data->email_protocol; + $config['smtp_host'] = $account_data->email_host; + $config['smtp_port'] = $account_data->email_port; + $config['smtp_user'] = $account_data->email_username; + $config['smtp_pass'] = $account_data->email_password; + } else { + $data['error'] = 'Invalid account settings.'; + } + $this->email->initialize($config); + + /* Sending email */ + $this->email->from('', 'Webzash'); + $this->email->to($this->input->post('email_to', TRUE)); + $this->email->subject($current_voucher_type['name'] . ' Voucher No. ' . full_voucher_number($voucher_type_id, $cur_voucher->number)); + $this->email->message($message); + if ($this->email->send()) + { + $data['message'] = "Email sent."; + $this->logger->write_message("success", "Emailed " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + } else { + $data['error'] = "Error sending email. Check you email settings."; + $this->logger->write_message("error", "Error emailing " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + } + $this->load->view('inventory/stockvoucher/email', $data); + return; + } + return; + } + + function addrow() + { + $i = time() + rand (0, time()) + rand (0, time()) + rand (0, time()); + $rate_item = array( + 'name' => 'rate_item[' . $i . ']', + 'id' => 'rate_item[' . $i . ']', + 'maxlength' => '5', + 'size' => '5', + 'value' => isset($dr_amount[$i]) ? $dr_amount[$i] : "", + 'class' => 'dr-item', + ); + $amount_item = array( + 'name' => 'amount_item[' . $i . ']', + 'id' => 'amount_item[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => isset($cr_amount[$i]) ? $cr_amount[$i] : "", + 'class' => 'cr-item', + ); + echo "<tr>"; + echo "<td>" . form_dropdown_dc('ledger_dc[' . $i . ']', 'D') . "</td>"; + echo "<td>" . form_input_ledger('ledger_id[' . $i . ']', '0') . "</td>"; + echo "<td>" . form_input($rate_item) . "</td>"; + echo "<td>" . form_input($amount_item) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addrow')) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deleterow')) . "</td>"; + echo "<td class="ledger-balance"><div></div></td>"; + echo "</tr>"; + return; + } + + function addstockrow() + { + $i = time() + rand (0, time()) + rand (0, time()) + rand (0, time()); + $stock_item_quantity = array( + 'name' => 'stock_item_quantity[' . $i . ']', + 'id' => 'stock_item_quantity[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => '', + 'class' => 'quantity-item', + ); + $stock_item_rate_per_unit = array( + 'name' => 'stock_item_rate_per_unit[' . $i . ']', + 'id' => 'stock_item_rate_per_unit[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => '', + 'class' => 'rate-item', + ); + $stock_item_discount = array( + 'name' => 'stock_item_discount[' . $i . ']', + 'id' => 'stock_item_discount[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => '', + 'class' => 'discount-item', + ); + $stock_item_amount = array( + 'name' => 'stock_item_amount[' . $i . ']', + 'id' => 'stock_item_amount[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => '', + 'class' => 'rate-item', + ); + + echo '<tr class="new-row">'; + echo "<td>" . form_input_stock_item('stock_item_id[' . $i . ']', 0) . "</td>"; + echo "<td>" . form_input($stock_item_quantity) . "</td>"; + echo "<td>" . form_input($stock_item_rate_per_unit) . "</td>"; + echo "<td>" . form_input($stock_item_discount) . "</td>"; + echo "<td>" . form_input($stock_item_amount) . "</td>"; + echo '<td>'; + echo img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Stock Item', 'class' => 'addstockrow')); + echo '</td>'; + echo '<td>'; + echo img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Stock Item', 'class' => 'deletestockrow')); + echo '</td>'; + echo '<td class="stock-item-balance"><div></div>'; + echo '</td>'; + echo '</tr>'; + return; + } +} + +/* End of file voucher.php */ +/* Location: ./system/application/controllers/inventory/stocktransfer.php */ diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index 57859f9..a24ba74 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -1546,4 +1546,4 @@ class StockVoucher extends Controller { }
/* End of file voucher.php */ -/* Location: ./system/application/controllers/voucher.php */ +/* Location: ./system/application/controllers/inventory/stockvoucher.php */ diff --git a/system/application/models/ledger_model.php b/system/application/models/ledger_model.php index 9a26499..53096e5 100644 --- a/system/application/models/ledger_model.php +++ b/system/application/models/ledger_model.php @@ -151,12 +151,18 @@ class Ledger_model extends Model { if ($current_voucher_type['base_type'] == '1') $html .= anchor('voucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "(" . $ledger->name . ")", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); else - $html .= anchor('inventory/stockvoucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "(" . $ledger->name . ")", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); + if ($current_voucher_type['stock_voucher_type'] == '3') + $html .= anchor('inventory/stocktransfer/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "(" . $ledger->name . ")", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); + else + $html .= anchor('inventory/stockvoucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "(" . $ledger->name . ")", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); else if ($current_voucher_type['base_type'] == '1') $html .= anchor('voucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, $ledger->name, array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); else - $html .= anchor('inventory/stockvoucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, $ledger->name, array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); + if ($current_voucher_type['stock_voucher_type'] == '3') + $html .= anchor('inventory/stocktransfer/view/' . $current_voucher_type['label'] . "/" . $voucher_id, $ledger->name, array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); + else + $html .= anchor('inventory/stockvoucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, $ledger->name, array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); return $html; } return; diff --git a/system/application/views/voucher/index.php b/system/application/views/voucher/index.php index 3285cf5..1e064c1 100644 --- a/system/application/views/voucher/index.php +++ b/system/application/views/voucher/index.php @@ -42,11 +42,20 @@ echo " " . anchor_popup('voucher/email/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/email.png", 'border' => '0', 'alt' => 'Email ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Email ' . $current_voucher_type['name'] . ' Voucher', 'width' => '500', 'height' => '300')) . " "; echo " " . anchor('voucher/download/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/save.png", 'border' => '0', 'alt' => 'Download ' . $current_voucher_type['name'] . ' Voucher', 'title' => "Download voucher")), array('title' => 'Download ' . $current_voucher_type['name'] . ' Voucher')) . "</td>"; } else { - echo "<td>" . anchor('inventory/stockvoucher/edit/' . $current_voucher_type['label'] . "/" . $row->id , "Edit", array('title' => 'Edit ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'red-link')) . " "; - echo " " . anchor('inventory/stockvoucher/delete/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Delete ' . $current_voucher_type['name'] . ' Voucher', 'class' => "confirmClick", 'title' => "Delete voucher")), array('title' => 'Delete ' . $current_voucher_type['name'] . ' Voucher')) . " "; - echo " " . anchor_popup('inventory/stockvoucher/printpreview/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/print.png", 'border' => '0', 'alt' => 'Print ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Print ' . $current_voucher_type['name']. ' Voucher', 'width' => '600', 'height' => '600')) . " "; - echo " " . anchor_popup('inventory/stockvoucher/email/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/email.png", 'border' => '0', 'alt' => 'Email ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Email ' . $current_voucher_type['name'] . ' Voucher', 'width' => '500', 'height' => '300')) . " "; - echo " " . anchor('inventory/stockvoucher/download/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/save.png", 'border' => '0', 'alt' => 'Download ' . $current_voucher_type['name'] . ' Voucher', 'title' => "Download voucher")), array('title' => 'Download ' . $current_voucher_type['name'] . ' Voucher')) . "</td>"; + if ($current_voucher_type['stock_voucher_type'] == '3') + { + echo "<td>" . anchor('inventory/stocktransfer/edit/' . $current_voucher_type['label'] . "/" . $row->id , "Edit", array('title' => 'Edit ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'red-link')) . " "; + echo " " . anchor('inventory/stocktransfer/delete/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Delete ' . $current_voucher_type['name'] . ' Voucher', 'class' => "confirmClick", 'title' => "Delete voucher")), array('title' => 'Delete ' . $current_voucher_type['name'] . ' Voucher')) . " "; + echo " " . anchor_popup('inventory/stocktransfer/printpreview/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/print.png", 'border' => '0', 'alt' => 'Print ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Print ' . $current_voucher_type['name']. ' Voucher', 'width' => '600', 'height' => '600')) . " "; + echo " " . anchor_popup('inventory/stocktransfer/email/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/email.png", 'border' => '0', 'alt' => 'Email ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Email ' . $current_voucher_type['name'] . ' Voucher', 'width' => '500', 'height' => '300')) . " "; + echo " " . anchor('inventory/stocktransfer/download/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/save.png", 'border' => '0', 'alt' => 'Download ' . $current_voucher_type['name'] . ' Voucher', 'title' => "Download voucher")), array('title' => 'Download ' . $current_voucher_type['name'] . ' Voucher')) . "</td>"; + } else { + echo "<td>" . anchor('inventory/stockvoucher/edit/' . $current_voucher_type['label'] . "/" . $row->id , "Edit", array('title' => 'Edit ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'red-link')) . " "; + echo " " . anchor('inventory/stockvoucher/delete/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Delete ' . $current_voucher_type['name'] . ' Voucher', 'class' => "confirmClick", 'title' => "Delete voucher")), array('title' => 'Delete ' . $current_voucher_type['name'] . ' Voucher')) . " "; + echo " " . anchor_popup('inventory/stockvoucher/printpreview/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/print.png", 'border' => '0', 'alt' => 'Print ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Print ' . $current_voucher_type['name']. ' Voucher', 'width' => '600', 'height' => '600')) . " "; + echo " " . anchor_popup('inventory/stockvoucher/email/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/email.png", 'border' => '0', 'alt' => 'Email ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Email ' . $current_voucher_type['name'] . ' Voucher', 'width' => '500', 'height' => '300')) . " "; + echo " " . anchor('inventory/stockvoucher/download/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/save.png", 'border' => '0', 'alt' => 'Download ' . $current_voucher_type['name'] . ' Voucher', 'title' => "Download voucher")), array('title' => 'Download ' . $current_voucher_type['name'] . ' Voucher')) . "</td>"; + } }
echo "</tr>";
commit ca0c3d8fd4697cdc2f4da1913b9e21157f3b2d20 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Wed Feb 23 22:17:14 2011 +0530
Added stock voucher edit
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index e284ac4..57859f9 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -567,7 +567,7 @@ class StockVoucher extends Controller { function edit($voucher_type, $voucher_id = 0) { /* Check access */ - if ( ! check_access('edit voucher')) + if ( ! check_access('edit stock voucher')) { $this->messages->add('Permission denied.', 'error'); redirect('inventory/stockvoucher/show/' . $voucher_type); @@ -626,6 +626,8 @@ class StockVoucher extends Controller { 'value' => $cur_voucher->narration, ); $data['voucher_id'] = $voucher_id; + $data['main_account_active'] = 0; + $data['main_entity_active'] = 0; $data['voucher_type_id'] = $voucher_type_id; $data['current_voucher_type'] = $current_voucher_type; $data['voucher_tag'] = $cur_voucher->tag_id; @@ -635,39 +637,58 @@ class StockVoucher extends Controller { /* Load current ledger details if not $_POST */ if ( ! $_POST) { - $this->db->from('voucher_items')->where('voucher_id', $voucher_id); + /* main - account */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1); + $cur_main_account_q = $this->db->get(); + $cur_main_account = $cur_main_account_q->row(); + $data['main_account_active'] = $cur_main_account->ledger_id; + + /* main - entity */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2); + $cur_main_entity_q = $this->db->get(); + $cur_main_entity = $cur_main_entity_q->row(); + $data['main_entity_active'] = $cur_main_entity->ledger_id; + + /* ledgers */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3); $cur_ledgers_q = $this->db->get(); - if ($cur_ledgers_q->num_rows <= 0) - { - $this->messages->add('No Ledger A/C's found!', 'error'); - } $counter = 0; foreach ($cur_ledgers_q->result() as $row) { $data['ledger_dc'][$counter] = $row->dc; $data['ledger_id'][$counter] = $row->ledger_id; - if ($row->dc == "D") - { - $data['dr_amount'][$counter] = $row->amount; - $data['cr_amount'][$counter] = ""; - } else { - $data['dr_amount'][$counter] = ""; - $data['cr_amount'][$counter] = $row->amount; - } + $data['rate_item'][$counter] = $row->stock_rate; + $data['amount_item'][$counter] = $row->amount; if ($row->reconciliation_date) $data['has_reconciliation'] = TRUE; $counter++; } - /* Two extra rows */ + /* one extra rows */ $data['ledger_dc'][$counter] = 'D'; $data['ledger_id'][$counter] = 0; - $data['dr_amount'][$counter] = ""; - $data['cr_amount'][$counter] = ""; + $data['rate_item'][$counter] = ""; + $data['amount_item'][$counter] = ""; $counter++; - $data['ledger_dc'][$counter] = 'D'; - $data['ledger_id'][$counter] = 0; - $data['dr_amount'][$counter] = ""; - $data['cr_amount'][$counter] = ""; + + /* stock items */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id); + $cur_stock_item_q = $this->db->get(); + $counter = 0; + foreach ($cur_stock_item_q->result() as $row) + { + $data['stock_item_id'][$counter] = $row->stock_item_id; + $data['stock_item_quantity'][$counter] = $row->quantity; + $data['stock_item_rate_per_unit'][$counter] = $row->rate_per_unit; + $data['stock_item_discount'][$counter] = $row->discount; + $data['stock_item_amount'][$counter] = $row->total; + $counter++; + } + /* one extra rows */ + $data['stock_item_id'][$counter] = '0'; + $data['stock_item_quantity'][$counter] = ""; + $data['stock_item_rate_per_unit'][$counter] = ""; + $data['stock_item_discount'][$counter] = ""; + $data['stock_item_amount'][$counter] = ""; $counter++; }
@@ -677,16 +698,31 @@ class StockVoucher extends Controller { else $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|required|is_natural_no_zero|uniquevouchernowithid[' . $voucher_type_id . '.' . $voucher_id . ']'); $this->form_validation->set_rules('voucher_date', 'Voucher Date', 'trim|required|is_date|is_date_within_range'); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->form_validation->set_rules('main_account', 'Purchase Ledger A/C', 'trim|required'); + $this->form_validation->set_rules('main_entity', 'Creditors (Supplier)', 'trim|required'); + } else { + $this->form_validation->set_rules('main_account', 'Sale Ledger A/C', 'trim|required'); + $this->form_validation->set_rules('main_entity', 'Debtor (Customer)', 'trim|required'); + } $this->form_validation->set_rules('voucher_narration', 'trim'); $this->form_validation->set_rules('voucher_tag', 'Tag', 'trim|is_natural');
/* Debit and Credit amount validation */ if ($_POST) { + foreach ($this->input->post('stock_item_id', TRUE) as $id => $stock_data) + { + $this->form_validation->set_rules('stock_item_quantity[' . $id . ']', 'Stock Item Quantity', 'trim|quantity'); + $this->form_validation->set_rules('stock_item_rate_per_unit[' . $id . ']', 'Stock Item Rate Per Unit', 'trim|currency'); + $this->form_validation->set_rules('stock_item_discount[' . $id . ']', 'Stock Item Discount', 'trim|discount'); + $this->form_validation->set_rules('stock_item_amount[' . $id . ']', 'Stock Item Amount', 'trim|currency'); + } foreach ($this->input->post('ledger_dc', TRUE) as $id => $ledger_data) { - $this->form_validation->set_rules('dr_amount[' . $id . ']', 'Debit Amount', 'trim|currency'); - $this->form_validation->set_rules('cr_amount[' . $id . ']', 'Credit Amount', 'trim|currency'); + $this->form_validation->set_rules('rate_item[' . $id . ']', 'Rate %', 'trim|rate'); + $this->form_validation->set_rules('amount_item[' . $id . ']', 'Ledger Amount', 'trim|currency'); } }
@@ -699,26 +735,108 @@ class StockVoucher extends Controller { $data['voucher_tag'] = $this->input->post('voucher_tag', TRUE); $data['has_reconciliation'] = $this->input->post('has_reconciliation', TRUE);
+ $data['main_account_active'] = $this->input->post('main_account', TRUE); + $data['main_entity_active'] = $this->input->post('main_entity', TRUE); + + $data['stock_item_id'] = $this->input->post('stock_item_id', TRUE); + $data['stock_item_quantity'] = $this->input->post('stock_item_quantity', TRUE); + $data['stock_item_rate_per_unit'] = $this->input->post('stock_item_rate_per_unit', TRUE); + $data['stock_item_discount'] = $this->input->post('stock_item_discount', TRUE); + $data['stock_item_amount'] = $this->input->post('stock_item_amount', TRUE); + $data['ledger_dc'] = $this->input->post('ledger_dc', TRUE); $data['ledger_id'] = $this->input->post('ledger_id', TRUE); - $data['dr_amount'] = $this->input->post('dr_amount', TRUE); - $data['cr_amount'] = $this->input->post('cr_amount', TRUE); + $data['rate_item'] = $this->input->post('rate_item', TRUE); + $data['amount_item'] = $this->input->post('amount_item', TRUE); }
if ($this->form_validation->run() == FALSE) { $this->messages->add(validation_errors(), 'error'); - $this->template->load('template', 'voucher/edit', $data); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); } else { - /* Checking for Valid Ledgers A/C and Debit and Credit Total */ + $data_main_account = $this->input->post('main_account', TRUE); + $data_main_entity = $this->input->post('main_entity', TRUE); + + $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); + $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); + $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); + $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); + $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); + $data_all_ledger_id = $this->input->post('ledger_id', TRUE); $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); - $data_all_dr_amount = $this->input->post('dr_amount', TRUE); - $data_all_cr_amount = $this->input->post('cr_amount', TRUE); - $dr_total = 0; - $cr_total = 0; - $bank_cash_present = FALSE; /* Whether atleast one Ledger A/C is Bank or Cash A/C */ - $non_bank_cash_present = FALSE; /* Whether atleast one Ledger A/C is NOT a Bank or Cash A/C */ + $data_all_rate_item = $this->input->post('rate_item', TRUE); + $data_all_amount_item = $this->input->post('amount_item', TRUE); + + $data_total_amount = 0; + + /* Setting Stock Item type */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $data_stock_item_type = 1; + else + $data_stock_item_type = 2; + + /* Checking for Valid Stock Ledger A/C - account */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 2); + else + $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 3); + $valid_main_account_q = $this->db->get(); + if ($valid_main_account_q->num_rows() < 1) + { + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->messages->add('Invalid Purchase Ledger A/C.', 'error'); + else + $this->messages->add('Invalid Sale Ledger A/C.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + /* Checking for Valid Stock Ledger A/C - entity */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 4)->or_where('type', 1); + else + $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 5)->or_where('type', 1); + $valid_main_account_q = $this->db->get(); + if ($valid_main_account_q->num_rows() < 1) + { + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->messages->add('Invalid Creditor (Supplier).', 'error'); + else + $this->messages->add('Invalid Debtor (Customer).', 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* Checking for Valid Stock Item A/C */ + $stock_item_present = FALSE; + $data_total_stock_amount = 0; + foreach ($data_all_stock_item_id as $id => $stock_data) + { + if ($data_all_stock_item_id[$id] < 1) + continue; + + /* Check for valid stock item id */ + $this->db->from('stock_items')->where('id', $data_all_stock_item_id[$id]); + $valid_stock_item_q = $this->db->get(); + if ($valid_stock_item_q->num_rows() < 1) + { + $this->messages->add('Invalid Stock Item.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + $stock_item_present = TRUE; + $data_total_stock_amount += $data_all_stock_item_amount[$id]; + } + if ( ! $stock_item_present) + { + $this->messages->add('No Stock Item selected.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* Checking for Valid Ledgers A/C */ + $data_total_ledger_amount = 0; foreach ($data_all_ledger_dc as $id => $ledger_data) { if ($data_all_ledger_id[$id] < 1) @@ -730,91 +848,30 @@ class StockVoucher extends Controller { if ($valid_ledger_q->num_rows() < 1) { $this->messages->add('Invalid Ledger A/C.', 'error'); - $this->template->load('template', 'voucher/edit', $data); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); return; - } else { - /* Check for valid ledger type */ - $valid_ledger = $valid_ledger_q->row(); - if ($current_voucher_type['bank_cash_ledger_restriction'] == '2') - { - if ($data_all_ledger_dc[$id] == 'D' && $valid_ledger->type == 1) - { - $bank_cash_present = TRUE; - } - if ($valid_ledger->type != 1) - $non_bank_cash_present = TRUE; - } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') - { - if ($data_all_ledger_dc[$id] == 'C' && $valid_ledger->type == 1) - { - $bank_cash_present = TRUE; - } - if ($valid_ledger->type != 1) - $non_bank_cash_present = TRUE; - } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '4') - { - if ($valid_ledger->type != 1) - { - $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers can have only Bank and Cash Ledgers A/C's.', 'error'); - $this->template->load('template', 'voucher/edit', $data); - return; - } - } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '5') - { - if ($valid_ledger->type == 1) - { - $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers cannot have Bank and Cash Ledgers A/C's.', 'error'); - $this->template->load('template', 'voucher/edit', $data); - return; - } - } - } - if ($data_all_ledger_dc[$id] == "D") - { - $dr_total += $data_all_dr_amount[$id]; - } else { - $cr_total += $data_all_cr_amount[$id]; } + if ($data_all_ledger_dc[$id] == 'D') + $data_total_ledger_amount += $data_all_amount_item[$id]; + else + $data_total_ledger_amount -= $data_all_amount_item[$id]; } - if ($dr_total != $cr_total) + + /* Total amount calculations */ + if ($current_voucher_type['stock_voucher_type'] == '1') { - $this->messages->add('Debit and Credit Total does not match!', 'error'); - $this->template->load('template', 'voucher/edit', $data); - return; - } else if ($dr_total == 0 && $cr_total == 0) { - $this->messages->add('Cannot save empty Voucher.', 'error'); - $this->template->load('template', 'voucher/edit', $data); - return; + $data_main_account_total = $data_total_stock_amount; + $data_main_entity_total = $data_total_stock_amount + $data_total_ledger_amount; + } else { + $data_main_account_total = $data_total_stock_amount + $data_total_ledger_amount; + $data_main_entity_total = $data_total_stock_amount; } - /* Check if atleast one Bank or Cash Ledger A/C is present */ - if ($current_voucher_type['bank_cash_ledger_restriction'] == '2') - { - if ( ! $bank_cash_present) - { - $this->messages->add('Need to Debit atleast one Bank or Cash A/C.', 'error'); - $this->template->load('template', 'voucher/edit', $data); - return; - } - if ( ! $non_bank_cash_present) - { - $this->messages->add('Need to Debit or Credit atleast one NON - Bank or Cash A/C.', 'error'); - $this->template->load('template', 'voucher/edit', $data); - return; - } - } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') + $data_total_amount = $data_total_stock_amount + $data_total_ledger_amount; + if ($data_total_amount < 0) { - if ( ! $bank_cash_present) - { - $this->messages->add('Need to Credit atleast one Bank or Cash A/C.', 'error'); - $this->template->load('template', 'voucher/edit', $data); - return; - } - if ( ! $non_bank_cash_present) - { - $this->messages->add('Need to Debit or Credit atleast one NON - Bank or Cash A/C.', 'error'); - $this->template->load('template', 'voucher/edit', $data); - return; - } + $this->messages->add($current_voucher_type['name'] . ' Voucher total cannot be negative.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; }
/* Updating main voucher */ @@ -847,71 +904,171 @@ class StockVoucher extends Controller { $this->db->trans_rollback(); $this->messages->add('Error updating Voucher A/C.', 'error'); $this->logger->write_message("error", "Error updating voucher details for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); - $this->template->load('template', 'voucher/edit', $data); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); return; }
/* TODO : Deleting all old ledger data, Bad solution */ - if ( ! $this->db->delete('voucher_items', array('voucher_id' => $voucher_id))) + if ( ! $this->db->delete('stock_voucher_items', array('voucher_id' => $voucher_id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting previous stock items from Voucher.', 'error'); + $this->logger->write_message("error", "Error deleting previous stock items from " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + if ( ! $this->db->delete('voucher_items', array('voucher_id' => $voucher_id))->where('stock_type', 3)) { $this->db->trans_rollback(); $this->messages->add('Error deleting previous Ledger A/C's from Voucher.', 'error'); $this->logger->write_message("error", "Error deleting previous voucher items for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); - $this->template->load('template', 'voucher/edit', $data); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* Updating main - account */ + $update_data = array( + 'ledger_id' => $data_main_account, + 'amount' => $data_main_account_total, + 'dc' => '', + 'reconciliation_date' => NULL, + 'stock_type' => 1, + 'stock_rate' => '', + ); + if ($current_voucher_type['stock_voucher_type'] == '1') + $update_data['dc'] = 'D'; + else + $update_data['dc'] = 'C'; + if ( ! $this->db->where('voucher_id', $voucher_id)->where('stock_type', 1)->update('voucher_items', $update_data)) + { + $this->db->trans_rollback(); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->messages->add('Error updating Purchase Ledger A/C of Voucher.', 'error'); + $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating purchase ledger " . "[id:" . $data_main_account . "]"); + } else { + $this->messages->add('Error updating Sale Ledger A/C of Voucher.', 'error'); + $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating sale ledger " . "[id:" . $data_main_account . "]"); + } + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + + /* Updating main - entity */ + $update_data = array( + 'ledger_id' => $data_main_entity, + 'amount' => $data_main_entity_total, + 'dc' => '', + 'reconciliation_date' => NULL, + 'stock_type' => 2, + 'stock_rate' => '', + ); + if ($current_voucher_type['stock_voucher_type'] == '1') + $insert_data['dc'] = 'C'; + else + $insert_data['dc'] = 'D'; + if ( ! $this->db->where('voucher_id', $voucher_id)->where('stock_type', 2)->update('voucher_items', $update_data)) + { + $this->db->trans_rollback(); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->messages->add('Error updating Creditor (Supplier) of Voucher.', 'error'); + $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating creditor ledger " . "[id:" . $data_main_entity . "]"); + } else { + $this->messages->add('Error updating Debtor (Customer) of Voucher.', 'error'); + $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debtor ledger " . "[id:" . $data_main_entity . "]"); + } + $this->template->load('template', 'inventory/stockvoucher/edit', $data); return; }
+ /* Adding stock items */ + $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); + $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); + $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); + $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); + $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); + + foreach ($data_all_stock_item_id as $id => $stock_data) + { + $data_stock_item_id = $data_all_stock_item_id[$id]; + + if ($data_stock_item_id < 1) + continue; + + $data_stock_item_quantity = $data_all_stock_item_quantity[$id]; + $data_stock_item_rate_per_unit = $data_all_stock_item_rate_per_unit[$id]; + $data_stock_item_discount = $data_all_stock_item_discount[$id]; + $data_stock_item_amount = $data_all_stock_item_amount[$id]; + + $insert_stock_data = array( + 'voucher_id' => $voucher_id, + 'stock_item_id' => $data_stock_item_id, + 'quantity' => $data_stock_item_quantity, + 'rate_per_unit' => $data_stock_item_rate_per_unit, + 'discount' => $data_stock_item_discount, + 'total' => $data_stock_item_amount, + 'type' => $data_stock_item_type, + ); + if ( ! $this->db->insert('stock_voucher_items', $insert_stock_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error adding Stock Item - ' . $data_ledger_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_ledger_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); + return; + } + } + /* Adding ledger accounts */ $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); $data_all_ledger_id = $this->input->post('ledger_id', TRUE); - $data_all_dr_amount = $this->input->post('dr_amount', TRUE); - $data_all_cr_amount = $this->input->post('cr_amount', TRUE); + $data_all_rate_item = $this->input->post('rate_item', TRUE); + $data_all_amount_item = $this->input->post('amount_item', TRUE);
- $dr_total = 0; - $cr_total = 0; foreach ($data_all_ledger_dc as $id => $ledger_data) { $data_ledger_dc = $data_all_ledger_dc[$id]; $data_ledger_id = $data_all_ledger_id[$id]; + if ($data_ledger_id < 1) continue; - $data_amount = 0; - if ($data_all_ledger_dc[$id] == "D") - { - $data_amount = $data_all_dr_amount[$id]; - $dr_total += $data_all_dr_amount[$id]; - } else { - $data_amount = $data_all_cr_amount[$id]; - $cr_total += $data_all_cr_amount[$id]; - } + + $data_rate = $data_all_rate_item[$id]; + $data_amount = $data_all_amount_item[$id];
$insert_ledger_data = array( 'voucher_id' => $voucher_id, 'ledger_id' => $data_ledger_id, 'amount' => $data_amount, 'dc' => $data_ledger_dc, + 'reconciliation_date' => NULL, + 'stock_type' => 3, + 'stock_rate' => $data_rate, ); if ( ! $this->db->insert('voucher_items', $insert_ledger_data)) { $this->db->trans_rollback(); $this->messages->add('Error adding Ledger A/C - ' . $data_ledger_id . ' to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding Ledger A/C item [id:" . $data_ledger_id . "] for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); - $this->template->load('template', 'voucher/edit', $data); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting voucher ledger item " . "[id:" . $data_ledger_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); return; } }
- /* Updating Debit and Credit Total in vouchers table */ + /* Updating Debit and Credit Total - vouchers */ $update_data = array( - 'dr_total' => $dr_total, - 'cr_total' => $cr_total, + 'dr_total' => $data_total_amount, + 'cr_total' => $data_total_amount, ); + if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) { $this->db->trans_rollback(); $this->messages->add('Error updating Voucher total.', 'error'); - $this->logger->write_message("error", "Error updating voucher total for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); - $this->template->load('template', 'voucher/edit', $data); + $this->logger->write_message("error", "Error updating " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debit and credit total"); + $this->template->load('template', 'inventory/stockvoucher/edit', $data); return; }
diff --git a/system/application/views/inventory/stockvoucher/edit.php b/system/application/views/inventory/stockvoucher/edit.php new file mode 100644 index 0000000..79ea9b4 --- /dev/null +++ b/system/application/views/inventory/stockvoucher/edit.php @@ -0,0 +1,473 @@ +<script type="text/javascript"> + +$(document).ready(function() { + + /***************************** STOCK ITEM *****************************/ + /* Stock Item dropdown changed */ + $('.stock-item-dropdown').live('change', function() { + if ($(this).val() == "0") { + $(this).parent().next().children().attr('value', ""); + $(this).parent().next().next().children().attr('value', ""); + $(this).parent().next().next().next().children().attr('value', ""); + $(this).parent().next().next().next().next().children().attr('value', ""); + $(this).parent().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().next().next().children().attr('disabled', 'disabled'); + } else { + $(this).parent().next().children().attr('disabled', ''); + $(this).parent().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().next().children().attr('disabled', ''); + $(this).parent().prev().children().trigger('change'); + } + var stockid = $(this).val(); + var rowid = $(this); + if (stockid > 0) { + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/balance') . '/\''; ?> + stockid, + success: function(data) { + rowid.parent().next().next().next().next().next().next().next().children().text(data); + rowid.parent().next().next().next().next().next().next().next().children().text(data); + } + }); + + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, + success: function(data) { + var sell_price = parseFloat(data); + if (isNaN(sell_price)) + sell_price = 0; + if (sell_price <= 0) + rowid.parent().next().next().children().val(""); + else + rowid.parent().next().next().children().val(sell_price); + } + }); + } else { + rowid.parent().next().next().next().next().next().next().next().children().text(""); + } + }); + + $('table td .quantity-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev()); + }); + + $('table td .rate-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev().prev()); + }); + + $('table td .discount-stock-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev().prev().prev()); + }); + + var calculateRowTotal = function(itemrow) { + var item_quantity = itemrow.next().children().val(); + var item_rate_per_unit = itemrow.next().next().children().val(); + var item_discount = itemrow.next().next().next().children().val(); + var is_percent = false; + + /* check whether discount is in percent or absolute value */ + if (item_discount != "") { + if (item_discount.match(/%$/)) + { + is_percent = true; + } + } + item_quantity = parseFloat(item_quantity); + item_rate_per_unit = parseFloat(item_rate_per_unit); + item_discount = parseFloat(item_discount); + if (isNaN(item_discount)) + item_discount = 0; + if ((!isNaN(item_quantity)) && (!isNaN(item_rate_per_unit))) + { + /* calculating total amount for each stock item */ + var item_amount; + if (is_percent) { + if (item_discount <= 100) + item_amount = ((item_quantity * item_rate_per_unit) * (100 - item_discount)) / 100; + } else { + item_amount = (item_quantity * item_rate_per_unit) - item_discount; + } + /* displaying total amount for each stock item */ + itemrow.next().next().next().next().children().val(item_amount); + itemrow.next().next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); + } + updateLedgerRowTotal(); + $('.recalculate').trigger('click'); + } + + $('table td .amount-stock-item').live('change', function() { + updateLedgerRowTotal(); + $('.recalculate').trigger('click'); + }); + + /* calculating stock total */ + var calculateStockTotal = function() { + var stock_total = 0; + $('table td .amount-stock-item').each(function(index) { + if ($(this).val() != "") + { + var item_amount = parseFloat($(this).val()); + if ( ! isNaN(item_amount)) + stock_total += item_amount; + } + }); + return stock_total; + } + + /* Add stock item row */ + $('table td .addstockrow').live('click', function() { + var cur_obj = this; + var add_image_url = $(cur_obj).attr('src'); + $(cur_obj).attr('src', <?php echo '\'' . asset_url() . 'images/icons/ajax.gif' . '\''; ?>); + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockvoucher/addstockrow') . '\''; ?>, + success: function(data) { + $(cur_obj).parent().parent().after(data); + $(cur_obj).attr('src', add_image_url); + $('.stock-item-dropdown').trigger('change'); + } + }); + }); + + /* Delete stock item row */ + $('table td .deletestockrow').live('click', function() { + $(this).parent().parent().remove(); + }); + + /******************************* LEDGER *******************************/ + /* Dr - Cr dropdown changed */ + $('.dc-dropdown').live('change', function() { + $('.recalculate').trigger('click'); + }); + + /* Ledger dropdown changed */ + $('.ledger-dropdown').live('change', function() { + if ($(this).val() == "0") { + $(this).parent().next().children().attr('value', ""); + $(this).parent().next().next().children().attr('value', ""); + $(this).parent().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().children().attr('disabled', 'disabled'); + } else { + $(this).parent().next().children().attr('disabled', ''); + $(this).parent().next().next().children().attr('disabled', ''); + $(this).parent().prev().children().trigger('change'); + } + + var ledgerid = $(this).val(); + var rowid = $(this); + if (ledgerid > 0) { + $.ajax({ + url: <?php echo '\'' . site_url('ledger/balance') . '/\''; ?> + ledgerid, + success: function(data) { + var ledger_bal = parseFloat(data); + if (isNaN(ledger_bal)) + ledger_bal = 0; + if (ledger_bal == 0) + rowid.parent().next().next().next().next().next().children().text("0"); + else if (ledger_bal < 0) + rowid.parent().next().next().next().next().next().children().text("Cr " + -data); + else + rowid.parent().next().next().next().next().next().children().text("Dr " + data); + } + }); + } else { + rowid.parent().next().next().next().next().next().children().text(""); + } + }); + + $('table td .rate-item').live('change', function() { + var rowid = $(this); + calculateLedgerRowTotal(rowid.parent().prev().prev()); + }); + + /* calculating ledger item amount */ + var calculateLedgerRowTotal = function(itemrow) { + var item_rate = itemrow.next().next().children().val(); + var is_percent = false; + var stock_total = calculateStockTotal(); + + /* check whether rate is in percent */ + if (item_rate != "") { + if (item_rate.match(/%$/)) + { + is_percent = true; + } + } + + item_rate = parseFloat(item_rate); + + if (!isNaN(item_rate)) + { + var item_amount; + if (is_percent) { + if (item_rate <= 100) { + item_amount = (((stock_total) * (100 + item_rate)) / 100) - (stock_total); + } + /* displaying total amount for each stock item */ + itemrow.next().next().next().children().val(item_amount); + itemrow.next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); + } + } + $('.recalculate').trigger('click'); + } + + /* updating ledger total */ + var updateLedgerRowTotal = function() { + $('table td .rate-item').each(function(index) { + var rowid = $(this); + calculateLedgerRowTotal(rowid.parent().prev().prev()); + }); + } + + $('table td .amount-item').live('change', function() { + $('.recalculate').trigger('click'); + }); + + /* calculating ledger total */ + var calculateLedgerTotal = function() { + var ledger_total = 0; + $('table td .amount-item').each(function(index) { + if ($(this).val() != "") + { + var item_amount = parseFloat($(this).val()); + if ( ! isNaN(item_amount)) + { + if ($(this).parent().prev().prev().prev().children().val() == 'D') { + ledger_total += item_amount; + } else if ($(this).parent().prev().prev().prev().children().val() == 'C') { + ledger_total -= item_amount; + } + } + } + }); + return ledger_total; + } + + /* Recalculate Total */ + $('table td .recalculate').live('click', function() { + var voucherTotal = calculateLedgerTotal() + calculateStockTotal(); + $("table tr #vr-total").text(voucherTotal); + if (voucherTotal >= 0) + $("table tr #vr-total").css("background-color", "#FFFF99"); + else + $("table tr #vr-total").css("background-color", "#FFE9E8"); + }); + + /* Delete ledger row */ + $('table td .deleterow').live('click', function() { + $(this).parent().parent().remove(); + }); + + /* Add ledger row */ + $('table td .addrow').live('click', function() { + var cur_obj = this; + var add_image_url = $(cur_obj).attr('src'); + $(cur_obj).attr('src', <?php echo '\'' . asset_url() . 'images/icons/ajax.gif' . '\''; ?>); + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockvoucher/addrow') . '\''; ?>, + success: function(data) { + $(cur_obj).parent().parent().after(data); + $(cur_obj).attr('src', add_image_url); + $('.ledger-dropdown').trigger('change'); + } + }); + }); + + /* On page load initiate all triggers */ + $('.dc-dropdown').trigger('change'); + $('.ledger-dropdown').trigger('change'); + $('.stock-item-dropdown').trigger('change'); +}); + +</script> + +<?php + echo form_open('inventory/stockvoucher/edit/' . $current_voucher_type['label'] . "/" . $voucher_id); + echo "<p>"; + echo "<span id="tooltip-target-1">"; + echo form_label('Voucher Number', 'voucher_number'); + echo " "; + echo $current_voucher_type['prefix'] . form_input($voucher_number) . $current_voucher_type['suffix']; + echo "</span>"; + echo "<span id="tooltip-content-1">Leave Voucher Number empty for auto numbering</span>"; + echo " "; + echo "<span id="tooltip-target-2">"; + echo form_label('Voucher Date', 'voucher_date'); + echo " "; + echo form_input_date_restrict($voucher_date); + echo "</span>"; + echo "<span id="tooltip-content-2">Date format is " . $this->config->item('account_date_format') . ".</span>"; + echo "</p>"; + + if ($current_voucher_type['stock_voucher_type'] == '1') + { + echo "<p>"; + echo "<table border=0 cellpadding=2>"; + echo "<tr>"; + echo "<td align="right">"; + echo form_label('Purchase Ledger A/C', 'main_account'); + echo "</td>"; + echo "<td>"; + echo form_input_ledger('main_account', $main_account_active, '', $type = 'purchase'); + echo "</td>"; + echo "</tr>"; + + echo "<tr>"; + echo "<td align="right">"; + echo form_label('Creditor (Supplier)', 'main_entity'); + echo "</td>"; + echo "<td>"; + echo form_input_ledger('main_entity', $main_entity_active, '', $type = 'creditor'); + echo "</td>"; + echo "</tr>"; + echo "</table>"; + echo "</p>"; + } else { + echo "<p>"; + echo "<table border=0 cellpadding=2>"; + echo "<tr>"; + echo "<td align="right">"; + echo form_label('Sales Ledger A/C', 'main_account'); + echo "</td>"; + echo "<td>"; + echo form_input_ledger('main_account', $main_account_active, '', $type = 'sale'); + echo "</td>"; + echo "</tr>"; + + echo "<tr>"; + echo "<td align="right">"; + echo form_label('Debtor (Customer)', 'main_entity'); + echo "</td>"; + echo "<td>"; + echo form_input_ledger('main_entity', $main_entity_active, '', $type = 'debtor'); + echo "</td>"; + echo "</tr>"; + echo "</table>"; + echo "</p>"; + } + + echo "<p></p>"; + + echo "<table class="voucher-table">"; + echo "<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate Per Unit</th><th>Discount %</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + + foreach ($stock_item_id as $i => $row) + { + $stock_item_quantity_item = array( + 'name' => 'stock_item_quantity[' . $i . ']', + 'id' => 'stock_item_quantity[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => isset($stock_item_quantity[$i]) ? $stock_item_quantity[$i] : '', + 'class' => 'quantity-stock-item', + ); + $stock_item_rate_per_unit_item = array( + 'name' => 'stock_item_rate_per_unit[' . $i . ']', + 'id' => 'stock_item_rate_per_unit[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => isset($stock_item_rate_per_unit[$i]) ? $stock_item_rate_per_unit[$i] : '', + 'class' => 'rate-stock-item', + ); + $stock_item_discount_item = array( + 'name' => 'stock_item_discount[' . $i . ']', + 'id' => 'stock_item_discount[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => isset($stock_item_discount[$i]) ? $stock_item_discount[$i] : '', + 'class' => 'discount-stock-item', + ); + $stock_item_amount_item = array( + 'name' => 'stock_item_amount[' . $i . ']', + 'id' => 'stock_item_amount[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => isset($stock_item_amount[$i]) ? $stock_item_amount[$i] : '', + 'class' => 'amount-stock-item', + ); + echo "<tr>"; + + echo "<td>" . form_input_stock_item('stock_item_id[' . $i . ']', isset($stock_item_id[$i]) ? $stock_item_id[$i] : 0) . "</td>"; + echo "<td>" . form_input($stock_item_quantity_item) . "</td>"; + echo "<td>" . form_input($stock_item_rate_per_unit_item) . "</td>"; + echo "<td>" . form_input($stock_item_discount_item) . "</td>"; + echo "<td>" . form_input($stock_item_amount_item) . "</td>"; + + echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addstockrow')) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deletestockrow')) . "</td>"; + + echo "<td class="stock-item-balance"><div></div></td>"; + + echo "</tr>"; + } + echo "</table>"; + + echo "<br />"; + echo "<br />"; + + echo "<table class="voucher-table">"; + echo "<thead><tr><th>Type</th><th>Ledger A/C</th><th>Rate %</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + + foreach ($ledger_dc as $i => $ledger) + { + $rate_item_item = array( + 'name' => 'rate_item[' . $i . ']', + 'id' => 'rate_item[' . $i . ']', + 'maxlength' => '5', + 'size' => '5', + 'value' => isset($rate_item[$i]) ? $rate_item[$i] : '', + 'class' => 'rate-item', + ); + $amount_item_item = array( + 'name' => 'amount_item[' . $i . ']', + 'id' => 'amount_item[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => isset($amount_item[$i]) ? $amount_item[$i] : '', + 'class' => 'amount-item', + ); + echo "<tr>"; + + echo "<td>" . form_dropdown_dc('ledger_dc[' . $i . ']', isset($ledger_dc[$i]) ? $ledger_dc[$i] : "D") . "</td>"; + echo "<td>" . form_input_ledger('ledger_id[' . $i . ']', isset($ledger_id[$i]) ? $ledger_id[$i] : 0) . "</td>"; + echo "<td>" . form_input($rate_item_item) . "</td>"; + echo "<td>" . form_input($amount_item_item) . "</td>"; + + echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addrow')) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deleterow')) . "</td>"; + + echo "<td class="ledger-balance"><div></div></td>"; + + echo "</tr>"; + } + + echo "<tr><td colspan="7"></td></tr>"; + echo "<tr id="voucher-total"><td colspan=3><strong>Total</strong></td><td id="vr-total">0</td><td>" . img(array('src' => asset_url() . "images/icons/gear.png", 'border' => '0', 'alt' => 'Recalculate Total', 'class' => 'recalculate', 'title' => 'Recalculate Total')) . "</td><td></td><td></td></tr>"; + + echo "</table>"; + + echo "<p>"; + echo form_label('Narration', 'voucher_narration'); + echo "<br />"; + echo form_textarea($voucher_narration); + echo "</p>"; + + echo "<p>"; + echo form_label('Tag', 'voucher_tag'); + echo " "; + echo form_dropdown('voucher_tag', $voucher_tags, $voucher_tag); + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Create'); + echo " "; + echo anchor('voucher/show/' . $current_voucher_type['label'], 'Back', array('title' => 'Back to ' . $current_voucher_type['name'] . ' Vouchers')); + echo "</p>"; + + echo form_close(); +
commit 28be2077192507420054a21938192cec60437e7b Author: Prashant P Shah pshah.mumbai@gmail.com Date: Tue Feb 22 22:12:15 2011 +0530
Updated stock voucher for sales
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index 6405fe4..e284ac4 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -333,8 +333,14 @@ class StockVoucher extends Controller { }
/* Total amount calculations */ - $data_main_account_total = $data_total_stock_amount; - $data_main_entity_total = $data_total_stock_amount + $data_total_ledger_amount; + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $data_main_account_total = $data_total_stock_amount; + $data_main_entity_total = $data_total_stock_amount + $data_total_ledger_amount; + } else { + $data_main_account_total = $data_total_stock_amount + $data_total_ledger_amount; + $data_main_entity_total = $data_total_stock_amount; + } $data_total_amount = $data_total_stock_amount + $data_total_ledger_amount; if ($data_total_amount < 0) {
commit 7437b4caf65f4f5ba76bc00e9b703789cf541573 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Mon Feb 21 22:45:17 2011 +0530
Added display of stock item closing quantity
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockitem.php b/system/application/controllers/inventory/stockitem.php index 0da4c4f..0da564b 100644 --- a/system/application/controllers/inventory/stockitem.php +++ b/system/application/controllers/inventory/stockitem.php @@ -412,9 +412,11 @@ class StockItem extends Controller { function balance($stock_ledger_id = 0) { if ($stock_ledger_id > 0) - echo $this->Stock_Item_model->get_stock_item_balance($stock_ledger_id); - else + { + echo $this->Stock_Item_model->get_closing_quantity($stock_ledger_id); + } else { echo ""; + } return; }
diff --git a/system/application/models/stock_item_model.php b/system/application/models/stock_item_model.php index c92d143..cb66ddf 100644 --- a/system/application/models/stock_item_model.php +++ b/system/application/models/stock_item_model.php @@ -30,9 +30,78 @@ class Stock_Item_model extends Model { return "(Error)"; }
- function get_stock_item_balance($stock_item_id) + function get_closing_quantity($stock_item_id) { - return '100'; + $this->db->from('stock_items')->where('id', $stock_item_id)->limit(1); + $stock_item_q = $this->db->get(); + if ( ! $stock_item = $stock_item_q->row()) + return 0; + + /* closing quantity */ + $opening_quantity = $stock_item->op_balance_quantity; + + $in_quantity = 0; + $this->db->select_sum('quantity', 'inquantity')->from('stock_voucher_items')->where('stock_item_id', $stock_item_id)->where('type', 1); + $in_quantity_q = $this->db->get(); + if ($in_quantity_d = $in_quantity_q->row()) + $in_quantity = $in_quantity_d->inquantity; + + $out_quantity = 0; + $this->db->select_sum('quantity', 'outquantity')->from('stock_voucher_items')->where('stock_item_id', $stock_item_id)->where('type', 2); + $out_quantity_q = $this->db->get(); + if ($out_quantity_d = $out_quantity_q->row()) + $out_quantity = $out_quantity_d->outquantity; + + $closing_quantity = $opening_quantity + $in_quantity - $out_quantity; + return $closing_quantity; + } + + /* TODO */ + function get_balance($stock_item_id) + { + $this->db->from('stock_items')->where('id', $stock_item_id)->limit(1); + $stock_item_q = $this->db->get(); + if ( ! $stock_item = $stock_item_q->row()) + return array(0, 0); + + /* closing quantity */ + $opening_quantity = $stock_item->op_balance_quantity; + $in_quantity = 0; + $this->db->select_sum('quantity', 'inquantity')->from('stock_voucher_items')->where('stock_item_id', $stock_item_id)->where('type', 1); + $in_quantity_q = $this->db->get(); + if ($in_quantity_d = $in_quantity_q->row()) + $in_quantity = $in_quantity_d->inquantity; + + $out_quantity = 0; + $this->db->select_sum('quantity', 'outquantity')->from('stock_voucher_items')->where('stock_item_id', $stock_item_id)->where('type', 2); + $out_quantity_q = $this->db->get(); + if ($out_quantity_d = $out_quantity_q->row()) + $out_quantity = $out_quantity_d->outquantity; + + $closing_quantity = $opening_quantity + $in_quantity - $out_quantity; + + /* closing profit or loss */ + $opening_amount = $stock_item->op_balance_total_value; + + /* standard method */ + if ($stock_item->costing_method == 1) + { + $in_amount = 0; + $this->db->select_sum('total', 'inamount')->from('stock_voucher_items')->where('stock_item_id', $stock_item_id)->where('type', 1); + $in_amount_q = $this->db->get(); + if ($in_amount_d = $in_amount_q->row()) + $in_amount = $in_amount_d->inamount; + + $out_amount = 0; + $this->db->select_sum('total', 'outamount')->from('stock_voucher_items')->where('stock_item_id', $stock_item_id)->where('type', 2); + $out_amount_q = $this->db->get(); + if ($out_amount_d = $out_amount_q->row()) + $out_amount = $out_amount_d->outamount; + + $closing_amount = $opening_amount + $in_amount - $out_amount; + + return array($closing_amount, $closing_quantity); + } }
function get_selling_price($stock_item_id) diff --git a/system/application/views/inventory/stockvoucher/add.php b/system/application/views/inventory/stockvoucher/add.php index 58ef702..bd77279 100644 --- a/system/application/views/inventory/stockvoucher/add.php +++ b/system/application/views/inventory/stockvoucher/add.php @@ -27,15 +27,8 @@ $(document).ready(function() { $.ajax({ url: <?php echo '\'' . site_url('inventory/stockitem/balance') . '/\''; ?> + stockid, success: function(data) { - var stock_bal = parseFloat(data); - if (isNaN(stock_bal)) - stock_bal = 0; - if (stock_bal == 0) - rowid.parent().next().next().next().next().next().next().children().text("0"); - else if (stock_bal < 0) - rowid.parent().next().next().next().next().next().next().next().children().text(data); - else - rowid.parent().next().next().next().next().next().next().next().children().text(data); + rowid.parent().next().next().next().next().next().next().next().children().text(data); + rowid.parent().next().next().next().next().next().next().next().children().text(data); } });
commit a6ba939245a30e25faf4f644da68f51a1c858853 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sun Feb 20 21:11:37 2011 +0530
Showing default selling price in stock voucher add
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockitem.php b/system/application/controllers/inventory/stockitem.php index 2d68c61..0da4c4f 100644 --- a/system/application/controllers/inventory/stockitem.php +++ b/system/application/controllers/inventory/stockitem.php @@ -417,6 +417,15 @@ class StockItem extends Controller { echo ""; return; } + + function sellprice($stock_ledger_id = 0) + { + if ($stock_ledger_id > 0) + echo $this->Stock_Item_model->get_selling_price($stock_ledger_id); + else + echo ""; + return; + } }
/* End of file stockitem.php */ diff --git a/system/application/models/stock_item_model.php b/system/application/models/stock_item_model.php index 1b4ae88..c92d143 100644 --- a/system/application/models/stock_item_model.php +++ b/system/application/models/stock_item_model.php @@ -34,4 +34,14 @@ class Stock_Item_model extends Model { { return '100'; } + + function get_selling_price($stock_item_id) + { + $this->db->from('stock_items')->where('id', $stock_item_id)->limit(1); + $stock_item_q = $this->db->get(); + if ($stock_item = $stock_item_q->row()) + return $stock_item->default_sell_price; + else + return ""; + } } diff --git a/system/application/views/inventory/stockvoucher/add.php b/system/application/views/inventory/stockvoucher/add.php index efb9e64..58ef702 100644 --- a/system/application/views/inventory/stockvoucher/add.php +++ b/system/application/views/inventory/stockvoucher/add.php @@ -38,6 +38,19 @@ $(document).ready(function() { rowid.parent().next().next().next().next().next().next().next().children().text(data); } }); + + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/sellprice') . '/\''; ?> + stockid, + success: function(data) { + var sell_price = parseFloat(data); + if (isNaN(sell_price)) + sell_price = 0; + if (sell_price <= 0) + rowid.parent().next().next().children().val(""); + else + rowid.parent().next().next().children().val(sell_price); + } + }); } else { rowid.parent().next().next().next().next().next().next().next().children().text(""); }
commit 9c848550ff6c0954b9c348dce4ee4b336c2d7f73 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sun Feb 20 17:23:56 2011 +0530
Documented database constants used in the application
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/welcome.php b/system/application/controllers/welcome.php index 8e3be2f..e52ebf2 100644 --- a/system/application/controllers/welcome.php +++ b/system/application/controllers/welcome.php @@ -1,5 +1,42 @@ <?php
+/** + * DATABASE CONSTANTS USED IN THE APPLICATION + * + * table: ledgers + * column : type + * 0 = General + * 1 = Bank or Cash A/C + * 2 = Purchase A/C + * 3 = Sale A/C + * 4 = Creditor + * 5 = Debtor + * + * table: voucher_types + * column : base_type + * 1 = Normal Voucher + * 2 = Stock Voucher + * column : stock_voucher_type + * 1 = Purchase + * 2 = Sale + * 3 = Stock Transfer + * + * table: voucher_items + * column : stock_type + * 0 = Not Applicable + * 1 = Account Ledger + * 2 = Entity Ledger + * 3 = Others Ledger + * + * table: stock_items + * column : costing_method + * + * table: stock_voucher_items + * column : type + * 1 = Incoming + * 2 = Outgoing + * + */ class Welcome extends Controller {
function Welcome()
commit 1ac5ca8eb70ea1e85216960f6b583c689c2ecc7a Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sun Feb 20 17:10:38 2011 +0530
Updated voucher types making some options readonly
- base_type cannot be changed later - stock_voucher_type cannot be changed later - added appropriate warning messages
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/assets/css/custom.css b/system/application/assets/css/custom.css index 8a3ecfd..9024c72 100644 --- a/system/application/assets/css/custom.css +++ b/system/application/assets/css/custom.css @@ -56,6 +56,12 @@ a.anchor-link-b { font-weight:italic; }
+.form-warning-text { + font-size:12px; + font-weight:italic; + color:#FF0000; +} + /******************************** PAGINATION **********************************/ #pagination-container { margin-top:20px; diff --git a/system/application/controllers/setting/vouchertypes.php b/system/application/controllers/setting/vouchertypes.php index c76bab7..1458303 100644 --- a/system/application/controllers/setting/vouchertypes.php +++ b/system/application/controllers/setting/vouchertypes.php @@ -291,7 +291,21 @@ class VoucherTypes extends Controller { 'value' => $voucher_type_data->zero_padding, );
- $data['voucher_type_base_types'] = array('1' => 'Normal Vocuher', '2' => 'Stock Voucher'); + switch ($voucher_type_data->base_type) + { + case 1: $data['base_type'] = 'Normal Vocuher'; $data['is_normal_voucher'] = TRUE; break; + case 2: $data['base_type'] = 'Stock Voucher'; $data['is_normal_voucher'] = FALSE; break; + default: $data['base_type'] = '(Invalid)'; $data['is_normal_voucher'] = TRUE; break; + } + + switch ($voucher_type_data->stock_voucher_type) + { + case 1: $data['stock_voucher_type'] = 'Purchase'; break; + case 2: $data['stock_voucher_type'] = 'Sale'; break; + case 3: $data['stock_voucher_type'] = 'Stock Transfer'; break; + default: $data['stock_voucher_type'] = '(Invalid)'; break; + } + $data['voucher_type_numberings'] = array('1' => 'Auto', '2' => 'Manual (required)', '3' => 'Manual (optional)'); $data['bank_cash_ledger_restrictions'] = array( '1' => 'Unrestricted', @@ -300,16 +314,9 @@ class VoucherTypes extends Controller { '4' => 'Only Bank or Cash A/C can be present on both Debit and Credit side', '5' => 'Only NON Bank or Cash A/C can be present on both Debit and Credit side', ); - $data['stock_voucher_types'] = array( - '1' => 'Purchase', - '2' => 'Sale', - '3' => 'Stock Transfer', - );
- $data['voucher_type_base_type_active'] = $voucher_type_data->base_type; $data['voucher_type_numbering_active'] = $voucher_type_data->numbering; $data['bank_cash_ledger_restriction_active'] = $voucher_type_data->bank_cash_ledger_restriction; - $data['stock_voucher_type_active'] = $voucher_type_data->stock_voucher_type; $data['voucher_type_id'] = $id;
/* Repopulating form */ @@ -322,10 +329,8 @@ class VoucherTypes extends Controller { $data['voucher_type_suffix']['value'] = $this->input->post('voucher_type_suffix', TRUE); $data['voucher_type_zero_padding']['value'] = $this->input->post('voucher_type_zero_padding', TRUE);
- $data['voucher_type_base_type_active'] = $this->input->post('voucher_type_base_type', TRUE); $data['voucher_type_numbering_active'] = $this->input->post('voucher_type_numbering', TRUE); $data['bank_cash_ledger_restriction_active'] = $this->input->post('bank_cash_ledger_restriction', TRUE); - $data['stock_voucher_type_active'] = $this->input->post('stock_voucher_type', TRUE); }
/* Form validations */ @@ -352,13 +357,8 @@ class VoucherTypes extends Controller { $data_voucher_type_prefix = $this->input->post('voucher_type_prefix', TRUE); $data_voucher_type_suffix = $this->input->post('voucher_type_suffix', TRUE); $data_voucher_type_zero_padding = $this->input->post('voucher_type_zero_padding', TRUE); - $data_voucher_type_base_type = $this->input->post('voucher_type_base_type', TRUE); $data_voucher_type_numbering = $this->input->post('voucher_type_numbering', TRUE); $data_bank_cash_ledger_restriction = $this->input->post('bank_cash_ledger_restriction', TRUE); - $data_stock_voucher_type = $this->input->post('stock_voucher_type', TRUE); - - if (($data_voucher_type_base_type < 1) or ($data_voucher_type_base_type > 2)) - $data_voucher_type_base_type = 1;
if (($data_voucher_type_numbering < 1) or ($data_voucher_type_numbering > 3)) $data_voucher_type_numbering = 1; @@ -366,21 +366,16 @@ class VoucherTypes extends Controller { if (($data_bank_cash_ledger_restriction < 1) or ($data_bank_cash_ledger_restriction > 5)) $data_bank_cash_ledger_restriction = 1;
- if (($data_stock_voucher_type < 1) or ($data_stock_voucher_type > 3)) - $data_stock_voucher_type = 1; - $this->db->trans_start(); $update_data = array( 'label' => $data_voucher_type_label, 'name' => $data_voucher_type_name, 'description' => $data_voucher_type_description, - 'base_type' => $data_voucher_type_base_type, 'numbering' => $data_voucher_type_numbering, 'prefix' => $data_voucher_type_prefix, 'suffix' => $data_voucher_type_suffix, 'zero_padding' => $data_voucher_type_zero_padding, 'bank_cash_ledger_restriction' => $data_bank_cash_ledger_restriction, - 'stock_voucher_type' => $data_stock_voucher_type, ); if ( ! $this->db->where('id', $data_voucher_type_id)->update('voucher_types', $update_data)) { diff --git a/system/application/views/admin/create.php b/system/application/views/admin/create.php index 130c295..04ccdc5 100644 --- a/system/application/views/admin/create.php +++ b/system/application/views/admin/create.php @@ -44,7 +44,9 @@ echo "<br />"; echo form_input_date($fy_start); echo "<br />"; - echo "<span class="form-help-text">Warning : Financial Year Start cannot be changed later.<br />Format as per 'Date Foramt' selected abobe.</span>"; + echo "<span class="form-warning-text">Warning: This option cannot be changed later.</span>"; + echo "<br />"; + echo "<span class="form-help-text">Note: Format as per 'Date Foramt' selected abobe.</span>"; echo "</p>";
echo "<p>"; @@ -52,7 +54,9 @@ echo "<br />"; echo form_input_date($fy_end); echo "<br />"; - echo "<span class="form-help-text">Warning : Financial Year End cannot be changed later.<br />Format as per 'Date Foramt' selected abobe.</span>"; + echo "<span class="form-warning-text">Warning: This option cannot be changed later.</span>"; + echo "<br />"; + echo "<span class="form-help-text">Note: Format as per 'Date Foramt' selected abobe.</span>"; echo "</p>";
echo "<p>"; diff --git a/system/application/views/setting/vouchertypes/add.php b/system/application/views/setting/vouchertypes/add.php index cb87bd6..94c0ac7 100644 --- a/system/application/views/setting/vouchertypes/add.php +++ b/system/application/views/setting/vouchertypes/add.php @@ -44,6 +44,8 @@ $(document).ready(function() { echo form_label('Base Type', 'voucher_type_base_type'); echo "<br />"; echo form_dropdown('voucher_type_base_type', $voucher_type_base_types, $voucher_type_base_type_active, 'id="voucher_type_base_type"'); + echo "<br />"; + echo "<span class="form-warning-text">Warning: This option cannot be changed later.</span>"; echo "</p>";
echo "<p id="bank_cash_ledger_restriction">"; @@ -56,6 +58,8 @@ $(document).ready(function() { echo form_label('Stock Voucher Type', 'stock_voucher_type'); echo "<br />"; echo form_dropdown('stock_voucher_type', $stock_voucher_types, $stock_voucher_type_active); + echo "<br />"; + echo "<span class="form-warning-text">Warning: This option cannot be changed later.</span>"; echo "</p>";
echo "<p>"; diff --git a/system/application/views/setting/vouchertypes/edit.php b/system/application/views/setting/vouchertypes/edit.php index a2eadfd..8414963 100644 --- a/system/application/views/setting/vouchertypes/edit.php +++ b/system/application/views/setting/vouchertypes/edit.php @@ -1,22 +1,3 @@ -<script type="text/javascript"> -$(document).ready(function() { - $('#voucher_type_base_type').change(function() { - if ($(this).val() == "1") { - $('#bank_cash_ledger_restriction').show(); - $('#stock_voucher_type').hide(); - } else if ($(this).val() == "2") { - $('#bank_cash_ledger_restriction').hide(); - $('#stock_voucher_type').show(); - } else { - $('#bank_cash_ledger_restriction').show(); - $('#stock_voucher_type').show(); - } - }); - /* initialize */ - $('#voucher_type_base_type').trigger('change'); -}); -</script> - <?php echo form_open('setting/vouchertypes/edit/' . $voucher_type_id);
@@ -43,20 +24,23 @@ $(document).ready(function() { echo "<p>"; echo form_label('Base Type', 'voucher_type_base_type'); echo "<br />"; - echo form_dropdown('voucher_type_base_type', $voucher_type_base_types, $voucher_type_base_type_active, 'id="voucher_type_base_type"'); - echo "</p>"; - - echo "<p id="bank_cash_ledger_restriction">"; - echo form_label('Restrictions', 'bank_cash_ledger_restriction'); - echo "<br />"; - echo form_dropdown('bank_cash_ledger_restriction', $bank_cash_ledger_restrictions, $bank_cash_ledger_restriction_active); + echo $base_type; echo "</p>";
- echo "<p id="stock_voucher_type">"; - echo form_label('Stock Voucher Type', 'stock_voucher_type'); - echo "<br />"; - echo form_dropdown('stock_voucher_type', $stock_voucher_types, $stock_voucher_type_active); - echo "</p>"; + if ($is_normal_voucher) + { + echo "<p id="bank_cash_ledger_restriction">"; + echo form_label('Restrictions', 'bank_cash_ledger_restriction'); + echo "<br />"; + echo form_dropdown('bank_cash_ledger_restriction', $bank_cash_ledger_restrictions, $bank_cash_ledger_restriction_active); + echo "</p>"; + } else { + echo "<p id="stock_voucher_type">"; + echo form_label('Stock Voucher Type', 'stock_voucher_type'); + echo "<br />"; + echo $stock_voucher_type; + echo "</p>"; + }
echo "<p>"; echo form_label('Voucher Numbering', 'voucher_type_numbering');
commit 141d376c218473a9d3222bb5f0230265ae18955e Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sun Feb 20 16:51:37 2011 +0530
Added stock transfer voucher type
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/setting/vouchertypes.php b/system/application/controllers/setting/vouchertypes.php index 9506bac..c76bab7 100644 --- a/system/application/controllers/setting/vouchertypes.php +++ b/system/application/controllers/setting/vouchertypes.php @@ -101,8 +101,9 @@ class VoucherTypes extends Controller { '5' => 'Only NON Bank or Cash A/C can be present on both Debit and Credit side', ); $data['stock_voucher_types'] = array( - '1' => 'Purchases', - '2' => 'Sales', + '1' => 'Purchase', + '2' => 'Sale', + '3' => 'Stock Transfer', );
$data['voucher_type_base_type_active'] = '1'; @@ -163,7 +164,7 @@ class VoucherTypes extends Controller { if (($data_bank_cash_ledger_restriction < 1) or ($data_bank_cash_ledger_restriction > 5)) $data_bank_cash_ledger_restriction = 1;
- if (($data_stock_voucher_type < 1) or ($data_stock_voucher_type > 2)) + if (($data_stock_voucher_type < 1) or ($data_stock_voucher_type > 3)) $data_stock_voucher_type = 1;
/* Calculating Voucher Type Id */ @@ -300,8 +301,9 @@ class VoucherTypes extends Controller { '5' => 'Only NON Bank or Cash A/C can be present on both Debit and Credit side', ); $data['stock_voucher_types'] = array( - '1' => 'Purchases', - '2' => 'Sales', + '1' => 'Purchase', + '2' => 'Sale', + '3' => 'Stock Transfer', );
$data['voucher_type_base_type_active'] = $voucher_type_data->base_type; @@ -364,7 +366,7 @@ class VoucherTypes extends Controller { if (($data_bank_cash_ledger_restriction < 1) or ($data_bank_cash_ledger_restriction > 5)) $data_bank_cash_ledger_restriction = 1;
- if (($data_stock_voucher_type < 1) or ($data_stock_voucher_type > 2)) + if (($data_stock_voucher_type < 1) or ($data_stock_voucher_type > 3)) $data_stock_voucher_type = 1;
$this->db->trans_start();
commit 586b560483116619bf752b03b1e6161e1b97bd03 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sun Feb 20 16:38:59 2011 +0530
Added type to stock_voucher_items table
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/db-update.txt b/db-update.txt index 1f0f404..ca9d8bf 100644 --- a/db-update.txt +++ b/db-update.txt @@ -48,6 +48,7 @@ CREATE TABLE IF NOT EXISTS stock_voucher_items ( rate_per_unit decimal(15,2) NOT NULL DEFAULT '0.00', discount varchar(15) NOT NULL, total decimal(15,2) NOT NULL DEFAULT '0.00', + type int(2) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
diff --git a/system/application/controllers/admin/schema.sql b/system/application/controllers/admin/schema.sql index fe23b30..ae1c25f 100644 --- a/system/application/controllers/admin/schema.sql +++ b/system/application/controllers/admin/schema.sql @@ -141,5 +141,6 @@ CREATE TABLE IF NOT EXISTS stock_voucher_items ( rate_per_unit decimal(15,2) NOT NULL DEFAULT '0.00', discount varchar(15) NOT NULL, total decimal(15,2) NOT NULL DEFAULT '0.00', + type int(2) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index 2cf3386..6405fe4 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -246,6 +246,12 @@ class StockVoucher extends Controller {
$data_total_amount = 0;
+ /* Setting Stock Item type */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $data_stock_item_type = 1; + else + $data_stock_item_type = 2; + /* Checking for Valid Stock Ledger A/C - account */ if ($current_voucher_type['stock_voucher_type'] == '1') $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 2); @@ -469,6 +475,7 @@ class StockVoucher extends Controller { 'rate_per_unit' => $data_stock_item_rate_per_unit, 'discount' => $data_stock_item_discount, 'total' => $data_stock_item_amount, + 'type' => $data_stock_item_type, ); if ( ! $this->db->insert('stock_voucher_items', $insert_stock_data)) {
commit 1f71e09c769291fcc1df2924702662437fa403ec Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sun Feb 20 16:25:44 2011 +0530
Added automatic calculation of total value of opening stock
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/views/inventory/stockitem/add.php b/system/application/views/inventory/stockitem/add.php index f10f5bd..011eba3 100644 --- a/system/application/views/inventory/stockitem/add.php +++ b/system/application/views/inventory/stockitem/add.php @@ -1,3 +1,36 @@ +<script type="text/javascript"> +$(document).ready(function() { + + /********************** STOCK ITEM TOTAL ******************************/ + $('#stock_item_op_quantity').live('change', function() { + updateTotalValue(); + }); + + $('#stock_item_op_rate_per_unit').live('change', function() { + updateTotalValue(); + }); + + var updateTotalValue = function() { + var quantity = $('#stock_item_op_quantity').val(); + var rate_per_unit = $('#stock_item_op_rate_per_unit').val(); + + quantity = parseFloat(quantity); + rate_per_unit = parseFloat(rate_per_unit); + + if ((!isNaN(quantity)) && (!isNaN(rate_per_unit))) + { + /* calculating total amount */ + var total_value; + total_value = quantity * rate_per_unit; + + /* displaying total amount for each stock item */ + $('#stock_item_op_total').val(total_value); + $('#stock_item_op_total').fadeTo('slow', 0.1).fadeTo('slow', 1); + } + } +}); +</script> + <?php echo form_open('inventory/stockitem/add');
diff --git a/system/application/views/inventory/stockitem/edit.php b/system/application/views/inventory/stockitem/edit.php index 0835134..884bbb8 100644 --- a/system/application/views/inventory/stockitem/edit.php +++ b/system/application/views/inventory/stockitem/edit.php @@ -1,3 +1,36 @@ +<script type="text/javascript"> +$(document).ready(function() { + + /********************** STOCK ITEM TOTAL ******************************/ + $('#stock_item_op_quantity').live('change', function() { + updateTotalValue(); + }); + + $('#stock_item_op_rate_per_unit').live('change', function() { + updateTotalValue(); + }); + + var updateTotalValue = function() { + var quantity = $('#stock_item_op_quantity').val(); + var rate_per_unit = $('#stock_item_op_rate_per_unit').val(); + + quantity = parseFloat(quantity); + rate_per_unit = parseFloat(rate_per_unit); + + if ((!isNaN(quantity)) && (!isNaN(rate_per_unit))) + { + /* calculating total amount */ + var total_value; + total_value = quantity * rate_per_unit; + + /* displaying total amount for each stock item */ + $('#stock_item_op_total').val(total_value); + $('#stock_item_op_total').fadeTo('slow', 0.1).fadeTo('slow', 1); + } + } +}); +</script> + <?php echo form_open('inventory/stockitem/edit/' . $stock_item_id);
commit 29a83817fe50fdbb01da998d3cfb7851bf1f315d Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sun Feb 20 16:10:16 2011 +0530
Added default selling price for stock items
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/db-update.txt b/db-update.txt index defcf60..1f0f404 100644 --- a/db-update.txt +++ b/db-update.txt @@ -36,6 +36,7 @@ CREATE TABLE IF NOT EXISTS stock_items ( op_balance_quantity float NOT NULL, op_balance_rate_per_unit decimal(15,2) NOT NULL, op_balance_total_value decimal(15,2) NOT NULL, + default_sell_price decimal(15,2) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
diff --git a/system/application/controllers/admin/schema.sql b/system/application/controllers/admin/schema.sql index c833b94..fe23b30 100644 --- a/system/application/controllers/admin/schema.sql +++ b/system/application/controllers/admin/schema.sql @@ -129,6 +129,7 @@ CREATE TABLE IF NOT EXISTS stock_items ( op_balance_quantity float NOT NULL, op_balance_rate_per_unit decimal(15,2) NOT NULL DEFAULT '0.00', op_balance_total_value decimal(15,2) NOT NULL DEFAULT '0.00', + default_sell_price decimal(15,2) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
diff --git a/system/application/controllers/inventory/stockitem.php b/system/application/controllers/inventory/stockitem.php index 5193c51..2d68c61 100644 --- a/system/application/controllers/inventory/stockitem.php +++ b/system/application/controllers/inventory/stockitem.php @@ -66,6 +66,13 @@ class StockItem extends Controller { 'size' => '40', 'value' => '', ); + $data['stock_item_default_sell_price'] = array( + 'name' => 'stock_item_default_sell_price', + 'id' => 'stock_item_default_sell_price', + 'maxlength' => '100', + 'size' => '40', + 'value' => '', + ); $data['stock_item_costing_methods'] = array( '1' => 'Last In First Out (LIFO)', '2' => 'First In First Out (FIFO)', @@ -84,6 +91,7 @@ class StockItem extends Controller { $this->form_validation->set_rules('stock_item_op_quantity', 'Opening Balance Quantity', 'trim|quantity'); $this->form_validation->set_rules('stock_item_op_rate_per_unit', 'Opening Balance Rate per unit', 'trim|currency'); $this->form_validation->set_rules('stock_item_op_total', 'Opening Balance Total value', 'trim|currency'); + $this->form_validation->set_rules('stock_item_default_sell_price', 'Default Selling Price', 'trim|currency');
/* Re-populating form */ if ($_POST) @@ -95,6 +103,7 @@ class StockItem extends Controller { $data['stock_item_op_quantity']['value'] = $this->input->post('stock_item_op_quantity', TRUE); $data['stock_item_op_rate_per_unit']['value'] = $this->input->post('stock_item_op_rate_per_unit', TRUE); $data['stock_item_op_total']['value'] = $this->input->post('stock_item_op_total', TRUE); + $data['stock_item_default_sell_price']['value'] = $this->input->post('stock_item_default_sell_price', TRUE); }
if ($this->form_validation->run() == FALSE) @@ -112,6 +121,7 @@ class StockItem extends Controller { $data_stock_item_op_quantity = $this->input->post('stock_item_op_quantity', TRUE); $data_stock_item_op_rate_per_unit = $this->input->post('stock_item_op_rate_per_unit', TRUE); $data_stock_item_op_total = $this->input->post('stock_item_op_total', TRUE); + $data_stock_item_default_sell_price = $this->input->post('stock_item_default_sell_price', TRUE);
/* Check if stock group present */ $this->db->select('id')->from('stock_groups')->where('id', $data_stock_item_group_id); @@ -143,6 +153,7 @@ class StockItem extends Controller { 'op_balance_quantity' => $data_stock_item_op_quantity, 'op_balance_rate_per_unit' => $data_stock_item_op_rate_per_unit, 'op_balance_total_value' => $data_stock_item_op_total, + 'default_sell_price' => $data_stock_item_default_sell_price, ); if ( ! $this->db->insert('stock_items', $insert_data)) { @@ -231,6 +242,13 @@ class StockItem extends Controller { 'size' => '40', 'value' => $stock_item_data->op_balance_total_value, ); + $data['stock_item_default_sell_price'] = array( + 'name' => 'stock_item_default_sell_price', + 'id' => 'stock_item_default_sell_price', + 'maxlength' => '100', + 'size' => '40', + 'value' => $stock_item_data->default_sell_price, + ); $data['stock_item_costing_methods'] = array( '1' => 'Last In First Out (LIFO)', '2' => 'First In First Out (FIFO)', @@ -250,6 +268,7 @@ class StockItem extends Controller { $this->form_validation->set_rules('stock_item_op_quantity', 'Opening Balance Quantity', 'trim|quantity'); $this->form_validation->set_rules('stock_item_op_rate_per_unit', 'Opening Balance Rate per unit', 'trim|currency'); $this->form_validation->set_rules('stock_item_op_total', 'Opening Balance Total value', 'trim|currency'); + $this->form_validation->set_rules('stock_item_default_sell_price', 'Default Selling Price', 'trim|currency');
/* Re-populating form */ if ($_POST) @@ -261,6 +280,7 @@ class StockItem extends Controller { $data['stock_item_op_quantity']['value'] = $this->input->post('stock_item_op_quantity', TRUE); $data['stock_item_op_rate_per_unit']['value'] = $this->input->post('stock_item_op_rate_per_unit', TRUE); $data['stock_item_op_total']['value'] = $this->input->post('stock_item_op_total', TRUE); + $data['stock_item_default_sell_price']['value'] = $this->input->post('stock_item_default_sell_price', TRUE); }
if ($this->form_validation->run() == FALSE) @@ -278,6 +298,7 @@ class StockItem extends Controller { $data_stock_item_op_quantity = $this->input->post('stock_item_op_quantity', TRUE); $data_stock_item_op_rate_per_unit = $this->input->post('stock_item_op_rate_per_unit', TRUE); $data_stock_item_op_total = $this->input->post('stock_item_op_total', TRUE); + $data_stock_item_default_sell_price = $this->input->post('stock_item_default_sell_price', TRUE); $data_id = $id;
/* Check if stock group present */ @@ -310,6 +331,7 @@ class StockItem extends Controller { 'op_balance_quantity' => $data_stock_item_op_quantity, 'op_balance_rate_per_unit' => $data_stock_item_op_rate_per_unit, 'op_balance_total_value' => $data_stock_item_op_total, + 'default_sell_price' => $data_stock_item_default_sell_price, ); if ( ! $this->db->where('id', $data_id)->update('stock_items', $update_data)) { diff --git a/system/application/views/inventory/stockitem/add.php b/system/application/views/inventory/stockitem/add.php index e9e8652..f10f5bd 100644 --- a/system/application/views/inventory/stockitem/add.php +++ b/system/application/views/inventory/stockitem/add.php @@ -50,6 +50,12 @@ echo "</p>";
echo "<p>"; + echo form_label('Default selling price', 'stock_item_default_sell_price'); + echo "<br />"; + echo form_input($stock_item_default_sell_price); + echo "</p>"; + + echo "<p>"; echo form_submit('submit', 'Create'); echo " "; echo anchor('inventory/account', 'Back', array('title' => 'Back to Inventory')); diff --git a/system/application/views/inventory/stockitem/edit.php b/system/application/views/inventory/stockitem/edit.php index f5fd1be..0835134 100644 --- a/system/application/views/inventory/stockitem/edit.php +++ b/system/application/views/inventory/stockitem/edit.php @@ -50,6 +50,12 @@ echo "</p>";
echo "<p>"; + echo form_label('Default selling price', 'stock_item_default_sell_price'); + echo "<br />"; + echo form_input($stock_item_default_sell_price); + echo "</p>"; + + echo "<p>"; echo form_submit('submit', 'Update'); echo " "; echo anchor('inventory/account', 'Back', array('title' => 'Back to Inventory'));
commit 4b762f403f4b1002943f8e05c2b5e9f758262a63 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sat Feb 19 22:40:13 2011 +0530
Added voucher item stock_rate column
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/db-update.txt b/db-update.txt index 3d39387..defcf60 100644 --- a/db-update.txt +++ b/db-update.txt @@ -10,6 +10,7 @@ ALTER TABLE voucher_types ADD stock_voucher_type INT(2) NOT NULL DEFAULT '1'; ALTER TABLE voucher_types CHANGE bank_cash_ledger_restriction bank_cash_ledger_restriction INT(2) NOT NULL DEFAULT '1';
ALTER TABLE voucher_items ADD stock_type INT(1) NOT NULL; +ALTER TABLE voucher_items ADD stock_rate VARCHAR(15) NOT NULL;
CREATE TABLE IF NOT EXISTS stock_units ( id int(11) NOT NULL AUTO_INCREMENT, diff --git a/system/application/controllers/admin/schema.sql b/system/application/controllers/admin/schema.sql index fc8de14..c833b94 100644 --- a/system/application/controllers/admin/schema.sql +++ b/system/application/controllers/admin/schema.sql @@ -52,6 +52,7 @@ CREATE TABLE IF NOT EXISTS voucher_items ( dc char(1) NOT NULL, reconciliation_date datetime NULL, stock_type int(1) NOT NULL, + stock_rate varchar(15) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index eb9dda3..2cf3386 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -205,13 +205,6 @@ class StockVoucher extends Controller { $data['rate_item'] = $this->input->post('rate_item', TRUE); $data['amount_item'] = $this->input->post('amount_item', TRUE); } else { - for ($count = 0; $count <= 1; $count++) - { - $data['ledger_dc'][$count] = "D"; - $data['ledger_id'][$count] = 0; - $data['rate_item'][$count] = ""; - $data['amount_item'][$count] = ""; - } for ($count = 0; $count <= 3; $count++) { $data['stock_item_id'][$count] = '0'; @@ -220,6 +213,13 @@ class StockVoucher extends Controller { $data['stock_item_discount'][$count] = ''; $data['stock_item_amount'][$count] = ''; } + for ($count = 0; $count <= 1; $count++) + { + $data['ledger_dc'][$count] = "D"; + $data['ledger_id'][$count] = 0; + $data['rate_item'][$count] = ""; + $data['amount_item'][$count] = ""; + } }
if ($this->form_validation->run() == FALSE) @@ -332,7 +332,6 @@ class StockVoucher extends Controller { $data_total_amount = $data_total_stock_amount + $data_total_ledger_amount; if ($data_total_amount < 0) { - $this->db->trans_rollback(); $this->messages->add($current_voucher_type['name'] . ' Voucher total cannot be negative.', 'error'); $this->template->load('template', 'inventory/stockvoucher/add', $data); return; @@ -390,6 +389,7 @@ class StockVoucher extends Controller { 'dc' => '', 'reconciliation_date' => NULL, 'stock_type' => 1, + 'stock_rate' => '', ); if ($current_voucher_type['stock_voucher_type'] == '1') $insert_data['dc'] = 'D'; @@ -420,6 +420,7 @@ class StockVoucher extends Controller { 'dc' => '', 'reconciliation_date' => NULL, 'stock_type' => 2, + 'stock_rate' => '', ); if ($current_voucher_type['stock_voucher_type'] == '1') $insert_data['dc'] = 'C'; @@ -489,11 +490,13 @@ class StockVoucher extends Controller { { $data_ledger_dc = $data_all_ledger_dc[$id]; $data_ledger_id = $data_all_ledger_id[$id]; - $data_amount = $data_all_amount_item[$id];
if ($data_ledger_id < 1) continue;
+ $data_rate = $data_all_rate_item[$id]; + $data_amount = $data_all_amount_item[$id]; + $insert_ledger_data = array( 'voucher_id' => $voucher_id, 'ledger_id' => $data_ledger_id, @@ -501,6 +504,7 @@ class StockVoucher extends Controller { 'dc' => $data_ledger_dc, 'reconciliation_date' => NULL, 'stock_type' => 3, + 'stock_rate' => $data_rate, ); if ( ! $this->db->insert('voucher_items', $insert_ledger_data)) { diff --git a/system/application/views/inventory/stockvoucher/add.php b/system/application/views/inventory/stockvoucher/add.php index 095dc03..efb9e64 100644 --- a/system/application/views/inventory/stockvoucher/add.php +++ b/system/application/views/inventory/stockvoucher/add.php @@ -90,10 +90,12 @@ $(document).ready(function() { itemrow.next().next().next().next().children().val(item_amount); itemrow.next().next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); } + updateLedgerRowTotal(); $('.recalculate').trigger('click'); }
$('table td .amount-stock-item').live('change', function() { + updateLedgerRowTotal(); $('.recalculate').trigger('click'); });
@@ -149,8 +151,6 @@ $(document).ready(function() { $(this).parent().next().next().children().attr('disabled', ''); $(this).parent().prev().children().trigger('change'); } - $(this).parent().next().children().trigger('change'); - $(this).parent().next().next().children().trigger('change');
var ledgerid = $(this).val(); var rowid = $(this); @@ -174,6 +174,50 @@ $(document).ready(function() { } });
+ $('table td .rate-item').live('change', function() { + var rowid = $(this); + calculateLedgerRowTotal(rowid.parent().prev().prev()); + }); + + /* calculating ledger item amount */ + var calculateLedgerRowTotal = function(itemrow) { + var item_rate = itemrow.next().next().children().val(); + var is_percent = false; + var stock_total = calculateStockTotal(); + + /* check whether rate is in percent */ + if (item_rate != "") { + if (item_rate.match(/%$/)) + { + is_percent = true; + } + } + + item_rate = parseFloat(item_rate); + + if (!isNaN(item_rate)) + { + var item_amount; + if (is_percent) { + if (item_rate <= 100) { + item_amount = (((stock_total) * (100 + item_rate)) / 100) - (stock_total); + } + /* displaying total amount for each stock item */ + itemrow.next().next().next().children().val(item_amount); + itemrow.next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); + } + } + $('.recalculate').trigger('click'); + } + + /* updating ledger total */ + var updateLedgerRowTotal = function() { + $('table td .rate-item').each(function(index) { + var rowid = $(this); + calculateLedgerRowTotal(rowid.parent().prev().prev()); + }); + } + $('table td .amount-item').live('change', function() { $('.recalculate').trigger('click'); }); diff --git a/system/application/views/inventory/stockvoucher/downloadpreview.php b/system/application/views/inventory/stockvoucher/downloadpreview.php index 52ee803..31987c0 100644 --- a/system/application/views/inventory/stockvoucher/downloadpreview.php +++ b/system/application/views/inventory/stockvoucher/downloadpreview.php @@ -130,7 +130,7 @@
<table class="print-voucher-table"> <thead> - <tr class="tr-title"><th>Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr> + <tr class="tr-title"><th>Ledger A/C</th>><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr> </thead> <tbody> <?php @@ -144,6 +144,7 @@ } else { echo "<td class=\"ledger-name item\">Cr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; } + echo "<td class=\"item\">" . $row->stock_rate . "</td>"; if ($row->dc == "D") { echo "<td class=\"ledger-dr item\">" . $currency . " " . $row->amount . "</td>"; @@ -154,7 +155,7 @@ } echo "</tr>"; } - echo "<tr class=\"tr-total\"><td class=\"total-name\">Total</td><td class=\"total-dr\">" . $currency . " " . $cur_voucher->dr_total . "</td><td class=\"total-cr\">" . $currency . " " . $cur_voucher->cr_total . "</td></tr>"; + echo "<tr class=\"tr-total\"><td class=\"total-name\" colspan=\"2\">Total</td><td class=\"total-dr\">" . $currency . " " . $cur_voucher->dr_total . "</td><td class=\"total-cr\">" . $currency . " " . $cur_voucher->cr_total . "</td></tr>"; ?> </tbody> </table> diff --git a/system/application/views/inventory/stockvoucher/emailpreview.php b/system/application/views/inventory/stockvoucher/emailpreview.php index a1f0bcc..e256c94 100644 --- a/system/application/views/inventory/stockvoucher/emailpreview.php +++ b/system/application/views/inventory/stockvoucher/emailpreview.php @@ -71,7 +71,7 @@
<table border=1 cellpadding=6> <thead> - <tr><th align="left">Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr> + <tr><th align="left">Ledger A/C</th><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr> </thead> <tbody> <?php @@ -85,6 +85,7 @@ } else { echo "<td>Cr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; } + echo "<td>" . $row->stock_rate . "</td>"; if ($row->dc == "D") { echo "<td>" . $currency . " " . $row->amount . "</td>"; @@ -95,7 +96,7 @@ } echo "</tr>"; } - echo "<tr><td>Total</td><td>" . $currency . " " . $cur_voucher->dr_total . "</td><td>" . $currency . " " . $cur_voucher->cr_total . "</td></tr>"; + echo "<tr><td colspan=\"2\">Total</td><td>" . $currency . " " . $cur_voucher->dr_total . "</td><td>" . $currency . " " . $cur_voucher->cr_total . "</td></tr>"; ?> </tbody> </table> diff --git a/system/application/views/inventory/stockvoucher/printpreview.php b/system/application/views/inventory/stockvoucher/printpreview.php index a7cd8e1..cdb545d 100644 --- a/system/application/views/inventory/stockvoucher/printpreview.php +++ b/system/application/views/inventory/stockvoucher/printpreview.php @@ -76,7 +76,7 @@
<table id="print-voucher-table"> <thead> - <tr class="tr-title"><th>Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr> + <tr class="tr-title"><th>Ledger A/C</th><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr> </thead> <tbody> <?php @@ -86,21 +86,22 @@ echo "<tr class=\"tr-ledger\">"; if ($row->dc == "D") { - echo "<td class=\"ledger-name item\">Dr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; + echo "<td class=\"item\">Dr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; } else { - echo "<td class=\"ledger-name item\">Cr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; + echo "<td class=\"item\">Cr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; } + echo "<td class=\"item\">" . $row->stock_rate . "</td>"; if ($row->dc == "D") { - echo "<td class=\"ledger-dr item\">" . $currency . " " . $row->amount . "</td>"; - echo "<td class=\"ledger-cr last-item\"></td>"; + echo "<td class=\"item\">" . $currency . " " . $row->amount . "</td>"; + echo "<td class=\"item last-item\"></td>"; } else { - echo "<td class=\"ledger-dr item\"></td>"; - echo "<td class=\"ledger-cr last-item\">" . $currency . " " . $row->amount . "</td>"; + echo "<td class=\"item\"></td>"; + echo "<td class=\"item last-item\">" . $currency . " " . $row->amount . "</td>"; } echo "</tr>"; } - echo "<tr class=\"tr-total\"><td class=\"total-name\">Total</td><td class=\"total-dr\">" . $currency . " " . $cur_voucher->dr_total . "</td><td class=\"total-cr\">" . $currency . " " . $cur_voucher->cr_total . "</td></tr>"; + echo "<tr class=\"tr-total\"><td class=\"total-name\" colspan=\"2\">Total</td><td class=\"total-dr\">" . $currency . " " . $cur_voucher->dr_total . "</td><td class=\"total-cr\">" . $currency . " " . $cur_voucher->cr_total . "</td></tr>"; ?> </tbody> </table> diff --git a/system/application/views/inventory/stockvoucher/view.php b/system/application/views/inventory/stockvoucher/view.php index 8448522..b46092d 100644 --- a/system/application/views/inventory/stockvoucher/view.php +++ b/system/application/views/inventory/stockvoucher/view.php @@ -60,13 +60,14 @@ foreach ($cur_voucher_stock_items->result() as $row) <br />
<table border=0 cellpadding=5 class="simple-table voucher-view-table"> -<thead><tr><th>Type</th><th>Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr></thead> +<thead><tr><th>Type</th><th>Ledger A/C</th><th>Rate</th><th>Dr Amount</th><th>Cr Amount</th></tr></thead> <?php foreach ($cur_voucher_ledgers->result() as $row) { echo "<tr>"; echo "<td>" . convert_dc($row->dc) . "</td>"; echo "<td>" . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; + echo "<td>" . $row->stock_rate . "</td>"; if ($row->dc == "D") { echo "<td>Dr " . $row->amount . "</td>"; @@ -78,7 +79,7 @@ foreach ($cur_voucher_ledgers->result() as $row) echo "</tr>"; } ?> -<tr class="voucher-total"><td colspan=2><strong>Total</strong></td><td id=dr-total>Dr <?php echo $cur_voucher->dr_total; ?></td><td id=cr-total">Cr <?php echo $cur_voucher->cr_total; ?></td></tr> +<tr class="voucher-total"><td colspan=3><strong>Total</strong></td><td id=dr-total>Dr <?php echo $cur_voucher->dr_total; ?></td><td id=cr-total">Cr <?php echo $cur_voucher->cr_total; ?></td></tr> <?php if ($cur_voucher->dr_total != $cur_voucher->cr_total) {
commit e175ed300ca3bb85b373ee9327cb82a41ddeb436 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Fri Feb 18 19:36:05 2011 +0530
Updated stock voucher total calculations
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index 62fe401..eb9dda3 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -279,6 +279,7 @@ class StockVoucher extends Controller {
/* Checking for Valid Stock Item A/C */ $stock_item_present = FALSE; + $data_total_stock_amount = 0; foreach ($data_all_stock_item_id as $id => $stock_data) { if ($data_all_stock_item_id[$id] < 1) @@ -294,6 +295,7 @@ class StockVoucher extends Controller { return; } $stock_item_present = TRUE; + $data_total_stock_amount += $data_all_stock_item_amount[$id]; } if ( ! $stock_item_present) { @@ -303,6 +305,7 @@ class StockVoucher extends Controller { }
/* Checking for Valid Ledgers A/C */ + $data_total_ledger_amount = 0; foreach ($data_all_ledger_dc as $id => $ledger_data) { if ($data_all_ledger_id[$id] < 1) @@ -317,6 +320,22 @@ class StockVoucher extends Controller { $this->template->load('template', 'inventory/stockvoucher/add', $data); return; } + if ($data_all_ledger_dc[$id] == 'D') + $data_total_ledger_amount += $data_all_amount_item[$id]; + else + $data_total_ledger_amount -= $data_all_amount_item[$id]; + } + + /* Total amount calculations */ + $data_main_account_total = $data_total_stock_amount; + $data_main_entity_total = $data_total_stock_amount + $data_total_ledger_amount; + $data_total_amount = $data_total_stock_amount + $data_total_ledger_amount; + if ($data_total_amount < 0) + { + $this->db->trans_rollback(); + $this->messages->add($current_voucher_type['name'] . ' Voucher total cannot be negative.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; }
/* Adding main voucher */ @@ -341,7 +360,6 @@ class StockVoucher extends Controller { $data_tag = NULL; $data_type = $voucher_type_id; $data_date = date_php_to_mysql($data_date); // Converting date to MySQL - $data_total_amount = 0; $voucher_id = NULL;
/* Adding Voucher */ @@ -368,7 +386,7 @@ class StockVoucher extends Controller { $insert_data = array( 'voucher_id' => $voucher_id, 'ledger_id' => $data_main_account, - 'amount' => $data_total_amount, + 'amount' => $data_main_account_total, 'dc' => '', 'reconciliation_date' => NULL, 'stock_type' => 1, @@ -398,7 +416,7 @@ class StockVoucher extends Controller { $insert_data = array( 'voucher_id' => $voucher_id, 'ledger_id' => $data_main_entity, - 'amount' => $data_total_amount, + 'amount' => $data_main_entity_total, 'dc' => '', 'reconciliation_date' => NULL, 'stock_type' => 2, @@ -443,8 +461,6 @@ class StockVoucher extends Controller { $data_stock_item_discount = $data_all_stock_item_discount[$id]; $data_stock_item_amount = $data_all_stock_item_amount[$id];
- $data_total_amount += $data_stock_item_amount; - $insert_stock_data = array( 'voucher_id' => $voucher_id, 'stock_item_id' => $data_stock_item_id, @@ -473,16 +489,11 @@ class StockVoucher extends Controller { { $data_ledger_dc = $data_all_ledger_dc[$id]; $data_ledger_id = $data_all_ledger_id[$id]; + $data_amount = $data_all_amount_item[$id];
if ($data_ledger_id < 1) continue;
- $data_amount = $data_all_amount_item[$id]; - if ($data_ledger_dc == "D") - $data_total_amount += $data_amount; - else - $data_total_amount -= $data_amount; - $insert_ledger_data = array( 'voucher_id' => $voucher_id, 'ledger_id' => $data_ledger_id, @@ -501,20 +512,12 @@ class StockVoucher extends Controller { } }
- if ($data_total_amount < 0) - { - $this->db->trans_rollback(); - $this->messages->add('Voucher total cannot be negative.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since voucher total is negative."); - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } - /* Updating Debit and Credit Total - vouchers */ $update_data = array( 'dr_total' => $data_total_amount, 'cr_total' => $data_total_amount, ); + if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) { $this->db->trans_rollback(); @@ -524,44 +527,6 @@ class StockVoucher extends Controller { return; }
- /* Updating Debit and Credit Total - main account */ - $update_data = array( - 'amount' => $data_total_amount, - ); - if ( ! $this->db->where('id', $main_voucher_id)->update('voucher_items', $update_data)) - { - $this->db->trans_rollback(); - if ($current_voucher_type['stock_voucher_type'] == '1') - { - $this->messages->add('Error updating Purchase Ledger A/C total.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating purchase ledger total"); - } else { - $this->messages->add('Error updating Sale Ledger A/C total.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating sale ledger total"); - } - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } - - /* Updating Debit and Credit Total - entity account */ - $update_data = array( - 'amount' => $data_total_amount, - ); - if ( ! $this->db->where('id', $entity_voucher_id)->update('voucher_items', $update_data)) - { - $this->db->trans_rollback(); - if ($current_voucher_type['stock_voucher_type'] == '1') - { - $this->messages->add('Error updating Creditor (Supplier) total.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating creditor (supplier) total"); - } else { - $this->messages->add('Error updating Debtor (Customer) total.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debtor (customer) total"); - } - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } - /* Success */ $this->db->trans_complete();
diff --git a/system/application/views/inventory/stockvoucher/view.php b/system/application/views/inventory/stockvoucher/view.php index 3bf649d..8448522 100644 --- a/system/application/views/inventory/stockvoucher/view.php +++ b/system/application/views/inventory/stockvoucher/view.php @@ -41,6 +41,7 @@ Voucher Date : <span class="bold"><?php echo date_mysql_to_php_display($cur_vouc <table border=0 cellpadding=5 class="simple-table voucher-view-table"> <thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate</th><th>Discount</th><th>Total</th></tr></thead> <?php +$stock_total = 0; foreach ($cur_voucher_stock_items->result() as $row) { echo "<tr>"; @@ -50,8 +51,10 @@ foreach ($cur_voucher_stock_items->result() as $row) echo "<td>" . $row->discount . "</td>"; echo "<td>" . $row->total . "</td>"; echo "</tr>"; + $stock_total += $row->total; } ?> +<tr class="voucher-total"><td colspan=4><strong>Total</strong></td><td id="stock-total"><?php echo convert_cur($stock_total); ?></td></tr> </table>
<br />
commit 6ea9ca8590eca53492f74803da8498f27819e4a7 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Fri Feb 18 19:04:01 2011 +0530
Updated voucher name for stock vouchers
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/models/ledger_model.php b/system/application/models/ledger_model.php index aa6291b..9a26499 100644 --- a/system/application/models/ledger_model.php +++ b/system/application/models/ledger_model.php @@ -132,7 +132,14 @@ class Ledger_model extends Model { $ledger_type = 'D';
$this->db->select('ledgers.name as name'); - $this->db->from('voucher_items')->join('ledgers', 'voucher_items.ledger_id = ledgers.id')->where('voucher_items.voucher_id', $voucher_id)->where('voucher_items.dc', $ledger_type); + $this->db->from('voucher_items')->join('ledgers', 'voucher_items.ledger_id = ledgers.id')->where('voucher_items.voucher_id', $voucher_id); + if ($current_voucher_type['base_type'] == '2') + { + $this->db->where('voucher_items.stock_type', 2); + } else { + $this->db->where('voucher_items.dc', $ledger_type); + } + $ledger_q = $this->db->get(); if ( ! $ledger = $ledger_q->row()) {
commit 62ff937b60ace61eeb0ea121182da3b186cfafe1 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Thu Feb 17 22:24:30 2011 +0530
Updated check for valid database tables
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/libraries/General.php b/system/application/libraries/General.php index eab6e19..677fdeb 100644 --- a/system/application/libraries/General.php +++ b/system/application/libraries/General.php @@ -71,7 +71,7 @@ class General { if ($CI->db->query("SHOW TABLES")) { /* Check for valid webzash database */ - $table_names = array('groups', 'ledgers', 'vouchers', 'voucher_items', 'tags', 'logs', 'settings'); + $table_names = array('groups', 'ledgers', 'voucher_types', 'vouchers', 'voucher_items', 'stock_units', 'stock_groups', 'stock_items', 'stock_voucher_items', 'tags', 'logs', 'settings'); foreach ($table_names as $id => $tbname) { $valid_db_q = mysql_query('DESC ' . $tbname);
commit 316774aec22cc32655c93a41255be5e53e61800e Author: Prashant P Shah pshah.mumbai@gmail.com Date: Thu Feb 17 22:05:41 2011 +0530
Udpated stock voucher total
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index a677545..62fe401 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -501,6 +501,15 @@ class StockVoucher extends Controller { } }
+ if ($data_total_amount < 0) + { + $this->db->trans_rollback(); + $this->messages->add('Voucher total cannot be negative.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since voucher total is negative."); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + /* Updating Debit and Credit Total - vouchers */ $update_data = array( 'dr_total' => $data_total_amount, diff --git a/system/application/views/inventory/stockvoucher/add.php b/system/application/views/inventory/stockvoucher/add.php index b3f814d..095dc03 100644 --- a/system/application/views/inventory/stockvoucher/add.php +++ b/system/application/views/inventory/stockvoucher/add.php @@ -90,6 +90,7 @@ $(document).ready(function() { itemrow.next().next().next().next().children().val(item_amount); itemrow.next().next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); } + $('.recalculate').trigger('click'); }
$('table td .amount-stock-item').live('change', function() { @@ -201,6 +202,10 @@ $(document).ready(function() { $('table td .recalculate').live('click', function() { var voucherTotal = calculateLedgerTotal() + calculateStockTotal(); $("table tr #vr-total").text(voucherTotal); + if (voucherTotal >= 0) + $("table tr #vr-total").css("background-color", "#FFFF99"); + else + $("table tr #vr-total").css("background-color", "#FFE9E8"); });
/* Delete ledger row */
commit f95137368bde3219028b211f7ba6096fca6632c1 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Thu Feb 17 21:51:48 2011 +0530
Updated stock voucher total
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/views/inventory/stockvoucher/add.php b/system/application/views/inventory/stockvoucher/add.php index 34b2e2f..b3f814d 100644 --- a/system/application/views/inventory/stockvoucher/add.php +++ b/system/application/views/inventory/stockvoucher/add.php @@ -93,7 +93,7 @@ $(document).ready(function() { }
$('table td .amount-stock-item').live('change', function() { - calculateStockTotal(); + $('.recalculate').trigger('click'); });
/* calculating stock total */ @@ -133,6 +133,7 @@ $(document).ready(function() { /******************************* LEDGER *******************************/ /* Dr - Cr dropdown changed */ $('.dc-dropdown').live('change', function() { + $('.recalculate').trigger('click'); });
/* Ledger dropdown changed */ @@ -172,9 +173,34 @@ $(document).ready(function() { } });
+ $('table td .amount-item').live('change', function() { + $('.recalculate').trigger('click'); + }); + + /* calculating ledger total */ + var calculateLedgerTotal = function() { + var ledger_total = 0; + $('table td .amount-item').each(function(index) { + if ($(this).val() != "") + { + var item_amount = parseFloat($(this).val()); + if ( ! isNaN(item_amount)) + { + if ($(this).parent().prev().prev().prev().children().val() == 'D') { + ledger_total += item_amount; + } else if ($(this).parent().prev().prev().prev().children().val() == 'C') { + ledger_total -= item_amount; + } + } + } + }); + return ledger_total; + } + /* Recalculate Total */ $('table td .recalculate').live('click', function() { - + var voucherTotal = calculateLedgerTotal() + calculateStockTotal(); + $("table tr #vr-total").text(voucherTotal); });
/* Delete ledger row */ @@ -273,7 +299,7 @@ $(document).ready(function() { echo "<p></p>";
echo "<table class="voucher-table">"; - echo "<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate Per Unit</th><th>Discount</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + echo "<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate Per Unit</th><th>Discount %</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>";
foreach ($stock_item_id as $i => $row) { @@ -366,7 +392,7 @@ $(document).ready(function() { }
echo "<tr><td colspan="7"></td></tr>"; - echo "<tr id="voucher-total"><td colspan=3><strong>Total</strong></td><td id="cr-total">0</td><td>" . img(array('src' => asset_url() . "images/icons/gear.png", 'border' => '0', 'alt' => 'Recalculate Total', 'class' => 'recalculate', 'title' => 'Recalculate Total')) . "</td><td></td><td></td></tr>"; + echo "<tr id="voucher-total"><td colspan=3><strong>Total</strong></td><td id="vr-total">0</td><td>" . img(array('src' => asset_url() . "images/icons/gear.png", 'border' => '0', 'alt' => 'Recalculate Total', 'class' => 'recalculate', 'title' => 'Recalculate Total')) . "</td><td></td><td></td></tr>";
echo "</table>";
commit fbb5116793b4718c1820b5eb7b63447459239341 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Wed Feb 16 22:43:36 2011 +0530
Added stock item total calculation in javascript
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/views/inventory/stockvoucher/add.php b/system/application/views/inventory/stockvoucher/add.php index 527a2a1..34b2e2f 100644 --- a/system/application/views/inventory/stockvoucher/add.php +++ b/system/application/views/inventory/stockvoucher/add.php @@ -62,7 +62,15 @@ $(document).ready(function() { var item_quantity = itemrow.next().children().val(); var item_rate_per_unit = itemrow.next().next().children().val(); var item_discount = itemrow.next().next().next().children().val(); + var is_percent = false;
+ /* check whether discount is in percent or absolute value */ + if (item_discount != "") { + if (item_discount.match(/%$/)) + { + is_percent = true; + } + } item_quantity = parseFloat(item_quantity); item_rate_per_unit = parseFloat(item_rate_per_unit); item_discount = parseFloat(item_discount); @@ -70,12 +78,38 @@ $(document).ready(function() { item_discount = 0; if ((!isNaN(item_quantity)) && (!isNaN(item_rate_per_unit))) { - var item_amount = (item_quantity * item_rate_per_unit) - item_discount; + /* calculating total amount for each stock item */ + var item_amount; + if (is_percent) { + if (item_discount <= 100) + item_amount = ((item_quantity * item_rate_per_unit) * (100 - item_discount)) / 100; + } else { + item_amount = (item_quantity * item_rate_per_unit) - item_discount; + } + /* displaying total amount for each stock item */ itemrow.next().next().next().next().children().val(item_amount); itemrow.next().next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); } }
+ $('table td .amount-stock-item').live('change', function() { + calculateStockTotal(); + }); + + /* calculating stock total */ + var calculateStockTotal = function() { + var stock_total = 0; + $('table td .amount-stock-item').each(function(index) { + if ($(this).val() != "") + { + var item_amount = parseFloat($(this).val()); + if ( ! isNaN(item_amount)) + stock_total += item_amount; + } + }); + return stock_total; + } + /* Add stock item row */ $('table td .addstockrow').live('click', function() { var cur_obj = this; @@ -273,7 +307,7 @@ $(document).ready(function() { 'maxlength' => '15', 'size' => '15', 'value' => isset($stock_item_amount[$i]) ? $stock_item_amount[$i] : '', - 'class' => 'rate-stock-item', + 'class' => 'amount-stock-item', ); echo "<tr>";
commit 2388c6435e9f930e5e63c90cd8de748c97d839fc Author: Prashant P Shah pshah.mumbai@gmail.com Date: Tue Feb 15 23:25:02 2011 +0530
Added discount validation
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index 1fa0ed0..a677545 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -173,7 +173,7 @@ class StockVoucher extends Controller { { $this->form_validation->set_rules('stock_item_quantity[' . $id . ']', 'Stock Item Quantity', 'trim|quantity'); $this->form_validation->set_rules('stock_item_rate_per_unit[' . $id . ']', 'Stock Item Rate Per Unit', 'trim|currency'); - $this->form_validation->set_rules('stock_item_discount[' . $id . ']', 'Stock Item Discount', 'trim|rate'); + $this->form_validation->set_rules('stock_item_discount[' . $id . ']', 'Stock Item Discount', 'trim|discount'); $this->form_validation->set_rules('stock_item_amount[' . $id . ']', 'Stock Item Amount', 'trim|currency'); } foreach ($this->input->post('ledger_dc', TRUE) as $id => $ledger_data) diff --git a/system/application/libraries/MY_Form_validation.php b/system/application/libraries/MY_Form_validation.php index a795821..7379e9c 100644 --- a/system/application/libraries/MY_Form_validation.php +++ b/system/application/libraries/MY_Form_validation.php @@ -118,6 +118,24 @@ class MY_Form_validation extends CI_Form_validation { } }
+ function discount($str) + { + $CI =& get_instance(); + if (preg_match('/^[-]/', $str)) + { + $CI->form_validation->set_message('discount', '%s cannot be negative.'); + return FALSE; + } + + if (preg_match('/^[0-9]*.?[0-9]{0,2}%?$/', $str)) + { + return TRUE; + } else { + $CI->form_validation->set_message('discount', '%s must be a valid percent or amount. Maximum 2 decimal places is allowed.'); + return FALSE; + } + } + function is_date($str) { $CI =& get_instance(); diff --git a/system/application/views/inventory/stockvoucher/add.php b/system/application/views/inventory/stockvoucher/add.php index ef0e6ee..527a2a1 100644 --- a/system/application/views/inventory/stockvoucher/add.php +++ b/system/application/views/inventory/stockvoucher/add.php @@ -243,7 +243,7 @@ $(document).ready(function() {
foreach ($stock_item_id as $i => $row) { - $stock_item_quantity = array( + $stock_item_quantity_item = array( 'name' => 'stock_item_quantity[' . $i . ']', 'id' => 'stock_item_quantity[' . $i . ']', 'maxlength' => '15', @@ -251,7 +251,7 @@ $(document).ready(function() { 'value' => isset($stock_item_quantity[$i]) ? $stock_item_quantity[$i] : '', 'class' => 'quantity-stock-item', ); - $stock_item_rate_per_unit = array( + $stock_item_rate_per_unit_item = array( 'name' => 'stock_item_rate_per_unit[' . $i . ']', 'id' => 'stock_item_rate_per_unit[' . $i . ']', 'maxlength' => '15', @@ -259,7 +259,7 @@ $(document).ready(function() { 'value' => isset($stock_item_rate_per_unit[$i]) ? $stock_item_rate_per_unit[$i] : '', 'class' => 'rate-stock-item', ); - $stock_item_discount = array( + $stock_item_discount_item = array( 'name' => 'stock_item_discount[' . $i . ']', 'id' => 'stock_item_discount[' . $i . ']', 'maxlength' => '15', @@ -267,7 +267,7 @@ $(document).ready(function() { 'value' => isset($stock_item_discount[$i]) ? $stock_item_discount[$i] : '', 'class' => 'discount-stock-item', ); - $stock_item_amount = array( + $stock_item_amount_item = array( 'name' => 'stock_item_amount[' . $i . ']', 'id' => 'stock_item_amount[' . $i . ']', 'maxlength' => '15', @@ -278,10 +278,10 @@ $(document).ready(function() { echo "<tr>";
echo "<td>" . form_input_stock_item('stock_item_id[' . $i . ']', isset($stock_item_id[$i]) ? $stock_item_id[$i] : 0) . "</td>"; - echo "<td>" . form_input($stock_item_quantity) . "</td>"; - echo "<td>" . form_input($stock_item_rate_per_unit) . "</td>"; - echo "<td>" . form_input($stock_item_discount) . "</td>"; - echo "<td>" . form_input($stock_item_amount) . "</td>"; + echo "<td>" . form_input($stock_item_quantity_item) . "</td>"; + echo "<td>" . form_input($stock_item_rate_per_unit_item) . "</td>"; + echo "<td>" . form_input($stock_item_discount_item) . "</td>"; + echo "<td>" . form_input($stock_item_amount_item) . "</td>";
echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addstockrow')) . "</td>"; echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deletestockrow')) . "</td>"; @@ -300,7 +300,7 @@ $(document).ready(function() {
foreach ($ledger_dc as $i => $ledger) { - $rate_item = array( + $rate_item_item = array( 'name' => 'rate_item[' . $i . ']', 'id' => 'rate_item[' . $i . ']', 'maxlength' => '5', @@ -308,7 +308,7 @@ $(document).ready(function() { 'value' => isset($rate_item[$i]) ? $rate_item[$i] : '', 'class' => 'rate-item', ); - $amount_item = array( + $amount_item_item = array( 'name' => 'amount_item[' . $i . ']', 'id' => 'amount_item[' . $i . ']', 'maxlength' => '15', @@ -320,8 +320,8 @@ $(document).ready(function() {
echo "<td>" . form_dropdown_dc('ledger_dc[' . $i . ']', isset($ledger_dc[$i]) ? $ledger_dc[$i] : "D") . "</td>"; echo "<td>" . form_input_ledger('ledger_id[' . $i . ']', isset($ledger_id[$i]) ? $ledger_id[$i] : 0) . "</td>"; - echo "<td>" . form_input($rate_item) . "</td>"; - echo "<td>" . form_input($amount_item) . "</td>"; + echo "<td>" . form_input($rate_item_item) . "</td>"; + echo "<td>" . form_input($amount_item_item) . "</td>";
echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addrow')) . "</td>"; echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deleterow')) . "</td>";
commit 12f943448b2bcfd77b1b9b8c9a0c854b399c802c Author: Prashant P Shah pshah.mumbai@gmail.com Date: Mon Feb 14 15:54:55 2011 +0530
Added stock voucher email, download, view
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/db-update.txt b/db-update.txt index 816fa11..3d39387 100644 --- a/db-update.txt +++ b/db-update.txt @@ -9,6 +9,8 @@ ALTER TABLE voucher_types ADD stock_voucher_type INT(2) NOT NULL DEFAULT '1';
ALTER TABLE voucher_types CHANGE bank_cash_ledger_restriction bank_cash_ledger_restriction INT(2) NOT NULL DEFAULT '1';
+ALTER TABLE voucher_items ADD stock_type INT(1) NOT NULL; + CREATE TABLE IF NOT EXISTS stock_units ( id int(11) NOT NULL AUTO_INCREMENT, symbol varchar(15) NOT NULL, diff --git a/system/application/controllers/admin/schema.sql b/system/application/controllers/admin/schema.sql index 98a91aa..fc8de14 100644 --- a/system/application/controllers/admin/schema.sql +++ b/system/application/controllers/admin/schema.sql @@ -51,6 +51,7 @@ CREATE TABLE IF NOT EXISTS voucher_items ( amount decimal(15,2) NOT NULL DEFAULT '0.00', dc char(1) NOT NULL, reconciliation_date datetime NULL, + stock_type int(1) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index 9585ca2..1fa0ed0 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -7,6 +7,7 @@ class StockVoucher extends Controller { parent::Controller(); $this->load->model('Voucher_model'); $this->load->model('Ledger_model'); + $this->load->model('Stock_Item_model'); $this->load->model('Tag_model'); return; } @@ -30,6 +31,13 @@ class StockVoucher extends Controller { $current_voucher_type = voucher_type_info($voucher_type_id); }
+ if ($current_voucher_type['base_type'] == '1') + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } + $this->template->set('page_title', 'View ' . $current_voucher_type['name'] . ' Voucher');
/* Load current voucher details */ @@ -39,18 +47,43 @@ class StockVoucher extends Controller { redirect('voucher/show/' . $current_voucher_type['label']); return; } - /* Load current voucher details */ - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); + + /* Load current voucher details - account, entity, ledgers */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); + $cur_voucher_main_account = $this->db->get(); + if ($cur_voucher_main_account->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); + $cur_voucher_main_entity = $this->db->get(); + if ($cur_voucher_main_entity->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); $cur_voucher_ledgers = $this->db->get(); if ($cur_voucher_ledgers->num_rows() < 1) { $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); } + + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); + $cur_voucher_stock_items = $this->db->get(); + if ($cur_voucher_stock_items->num_rows() < 1) + { + $this->messages->add('Voucher has no associated stock items.', 'error'); + } + $data['cur_voucher'] = $cur_voucher; + $data['cur_voucher_main_account'] = $cur_voucher_main_account; + $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; + $data['cur_voucher_stock_items'] = $cur_voucher_stock_items; $data['voucher_type_id'] = $voucher_type_id; $data['current_voucher_type'] = $current_voucher_type; - $this->template->load('template', 'voucher/view', $data); + $this->template->load('template', 'inventory/stockvoucher/view', $data); return; }
@@ -337,6 +370,8 @@ class StockVoucher extends Controller { 'ledger_id' => $data_main_account, 'amount' => $data_total_amount, 'dc' => '', + 'reconciliation_date' => NULL, + 'stock_type' => 1, ); if ($current_voucher_type['stock_voucher_type'] == '1') $insert_data['dc'] = 'D'; @@ -365,6 +400,8 @@ class StockVoucher extends Controller { 'ledger_id' => $data_main_entity, 'amount' => $data_total_amount, 'dc' => '', + 'reconciliation_date' => NULL, + 'stock_type' => 2, ); if ($current_voucher_type['stock_voucher_type'] == '1') $insert_data['dc'] = 'C'; @@ -451,6 +488,8 @@ class StockVoucher extends Controller { 'ledger_id' => $data_ledger_id, 'amount' => $data_amount, 'dc' => $data_ledger_dc, + 'reconciliation_date' => NULL, + 'stock_type' => 3, ); if ( ! $this->db->insert('voucher_items', $insert_ledger_data)) { @@ -981,10 +1020,9 @@ class StockVoucher extends Controller { { $this->load->helper('download'); $this->load->model('Setting_model'); - $this->load->model('Ledger_model');
/* Check access */ - if ( ! check_access('download voucher')) + if ( ! check_access('download stock voucher')) { $this->messages->add('Permission denied.', 'error'); redirect('inventory/stockvoucher/show/' . $voucher_type); @@ -1002,6 +1040,13 @@ class StockVoucher extends Controller { $current_voucher_type = voucher_type_info($voucher_type_id); }
+ if ($current_voucher_type['base_type'] == '1') + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } + /* Load current voucher details */ if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) { @@ -1010,36 +1055,45 @@ class StockVoucher extends Controller { return; }
- $data['voucher_type_id'] = $voucher_type_id; - $data['current_voucher_type'] = $current_voucher_type; - $data['voucher_number'] = $cur_voucher->number; - $data['voucher_date'] = date_mysql_to_php_display($cur_voucher->date); - $data['voucher_dr_total'] = $cur_voucher->dr_total; - $data['voucher_cr_total'] = $cur_voucher->cr_total; - $data['voucher_narration'] = $cur_voucher->narration; - - /* Getting Ledger details */ - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->order_by('dc', 'desc'); - $ledger_q = $this->db->get(); - $counter = 0; - $data['ledger_data'] = array(); - if ($ledger_q->num_rows() > 0) + /* Load current voucher details - account, entity, ledgers */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); + $cur_voucher_main_account = $this->db->get(); + if ($cur_voucher_main_account->num_rows() < 1) { - foreach ($ledger_q->result() as $row) - { - $data['ledger_data'][$counter] = array( - 'id' => $row->ledger_id, - 'name' => $this->Ledger_model->get_name($row->ledger_id), - 'dc' => $row->dc, - 'amount' => $row->amount, - ); - $counter++; - } + $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); + $cur_voucher_main_entity = $this->db->get(); + if ($cur_voucher_main_entity->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); + $cur_voucher_ledgers = $this->db->get(); + if ($cur_voucher_ledgers->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); + } + + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); + $cur_voucher_stock_items = $this->db->get(); + if ($cur_voucher_stock_items->num_rows() < 1) + { + $this->messages->add('Voucher has no associated stock items.', 'error'); }
+ $data['cur_voucher'] = $cur_voucher; + $data['cur_voucher_main_account'] = $cur_voucher_main_account; + $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; + $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; + $data['cur_voucher_stock_items'] = $cur_voucher_stock_items; + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + /* Download Voucher */ $file_name = $current_voucher_type['name'] . '_voucher_' . $cur_voucher->number . ".html"; - $download_data = $this->load->view('voucher/downloadpreview', $data, TRUE); + $download_data = $this->load->view('inventory/stockvoucher/downloadpreview', $data, TRUE); force_download($file_name, $download_data); return; } @@ -1047,10 +1101,9 @@ class StockVoucher extends Controller { function printpreview($voucher_type, $voucher_id = 0) { $this->load->model('Setting_model'); - $this->load->model('Ledger_model');
/* Check access */ - if ( ! check_access('print voucher')) + if ( ! check_access('print stock voucher')) { $this->messages->add('Permission denied.', 'error'); redirect('inventory/stockvoucher/show/' . $voucher_type); @@ -1068,6 +1121,13 @@ class StockVoucher extends Controller { $current_voucher_type = voucher_type_info($voucher_type_id); }
+ if ($current_voucher_type['base_type'] == '1') + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } + /* Load current voucher details */ if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) { @@ -1076,45 +1136,53 @@ class StockVoucher extends Controller { return; }
- $data['voucher_type_id'] = $voucher_type_id; - $data['current_voucher_type'] = $current_voucher_type; - $data['voucher_number'] = $cur_voucher->number; - $data['voucher_date'] = date_mysql_to_php_display($cur_voucher->date); - $data['voucher_dr_total'] = $cur_voucher->dr_total; - $data['voucher_cr_total'] = $cur_voucher->cr_total; - $data['voucher_narration'] = $cur_voucher->narration; - - /* Getting Ledger details */ - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->order_by('dc', 'desc'); - $ledger_q = $this->db->get(); - $counter = 0; - $data['ledger_data'] = array(); - if ($ledger_q->num_rows() > 0) + /* Load current voucher details - account, entity, ledgers */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); + $cur_voucher_main_account = $this->db->get(); + if ($cur_voucher_main_account->num_rows() < 1) { - foreach ($ledger_q->result() as $row) - { - $data['ledger_data'][$counter] = array( - 'id' => $row->ledger_id, - 'name' => $this->Ledger_model->get_name($row->ledger_id), - 'dc' => $row->dc, - 'amount' => $row->amount, - ); - $counter++; - } + $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); + $cur_voucher_main_entity = $this->db->get(); + if ($cur_voucher_main_entity->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); + $cur_voucher_ledgers = $this->db->get(); + if ($cur_voucher_ledgers->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); }
- $this->load->view('voucher/printpreview', $data); + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); + $cur_voucher_stock_items = $this->db->get(); + if ($cur_voucher_stock_items->num_rows() < 1) + { + $this->messages->add('Voucher has no associated stock items.', 'error'); + } + + $data['cur_voucher'] = $cur_voucher; + $data['cur_voucher_main_account'] = $cur_voucher_main_account; + $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; + $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; + $data['cur_voucher_stock_items'] = $cur_voucher_stock_items; + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + + $this->load->view('inventory/stockvoucher/printpreview', $data); return; }
function email($voucher_type, $voucher_id = 0) { $this->load->model('Setting_model'); - $this->load->model('Ledger_model'); $this->load->library('email');
/* Check access */ - if ( ! check_access('email voucher')) + if ( ! check_access('email stock voucher')) { $this->messages->add('Permission denied.', 'error'); redirect('inventory/stockvoucher/show/' . $voucher_type); @@ -1142,6 +1210,34 @@ class StockVoucher extends Controller { return; }
+ /* Load current voucher details - account, entity, ledgers */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 1)->order_by('id', 'asc'); + $cur_voucher_main_account = $this->db->get(); + if ($cur_voucher_main_account->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Purchase or Sale Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 2)->order_by('id', 'asc'); + $cur_voucher_main_entity = $this->db->get(); + if ($cur_voucher_main_entity->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Debtor or Creditor Ledger A/C.', 'error'); + } + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->where('stock_type', 3)->order_by('id', 'asc'); + $cur_voucher_ledgers = $this->db->get(); + if ($cur_voucher_ledgers->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); + } + + /* Load current stock items details */ + $this->db->from('stock_voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); + $cur_voucher_stock_items = $this->db->get(); + if ($cur_voucher_stock_items->num_rows() < 1) + { + $this->messages->add('Voucher has no associated stock items.', 'error'); + } + $data['voucher_type_id'] = $voucher_type_id; $data['current_voucher_type'] = $current_voucher_type; $data['voucher_id'] = $voucher_id; @@ -1165,40 +1261,19 @@ class StockVoucher extends Controller { if ($this->form_validation->run() == FALSE) { $data['error'] = validation_errors(); - $this->load->view('voucher/email', $data); + $this->load->view('inventory/stockvoucher/email', $data); return; } else { - $voucher_data['voucher_type_id'] = $voucher_type_id; - $voucher_data['current_voucher_type'] = $current_voucher_type; - $voucher_data['voucher_number'] = $cur_voucher->number; - $voucher_data['voucher_date'] = date_mysql_to_php_display($cur_voucher->date); - $voucher_data['voucher_dr_total'] = $cur_voucher->dr_total; - $voucher_data['voucher_cr_total'] = $cur_voucher->cr_total; - $voucher_data['voucher_narration'] = $cur_voucher->narration; - - /* Getting Ledger details */ - $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->order_by('dc', 'desc'); - $ledger_q = $this->db->get(); - $counter = 0; - $voucher_data['ledger_data'] = array(); - if ($ledger_q->num_rows() > 0) - { - foreach ($ledger_q->result() as $row) - { - $voucher_data['ledger_data'][$counter] = array( - 'id' => $row->ledger_id, - 'name' => $this->Ledger_model->get_name($row->ledger_id), - 'dc' => $row->dc, - 'amount' => $row->amount, - ); - $counter++; - } - } + $data['cur_voucher'] = $cur_voucher; + $data['cur_voucher_main_account'] = $cur_voucher_main_account; + $data['cur_voucher_main_entity'] = $cur_voucher_main_entity; + $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; + $data['cur_voucher_stock_items'] = $cur_voucher_stock_items;
/* Preparing message */ - $message = $this->load->view('voucher/emailpreview', $voucher_data, TRUE); + $message = $this->load->view('inventory/stockvoucher/emailpreview', $data, TRUE);
/* Getting email configuration */ $config['smtp_timeout'] = '30'; @@ -1230,7 +1305,7 @@ class StockVoucher extends Controller { $data['error'] = "Error sending email. Check you email settings."; $this->logger->write_message("error", "Error emailing " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); } - $this->load->view('voucher/email', $data); + $this->load->view('inventory/stockvoucher/email', $data); return; } return; diff --git a/system/application/controllers/voucher.php b/system/application/controllers/voucher.php index eeb24af..312728f 100644 --- a/system/application/controllers/voucher.php +++ b/system/application/controllers/voucher.php @@ -207,6 +207,13 @@ class Voucher extends Controller { $current_voucher_type = voucher_type_info($voucher_type_id); }
+ if ($current_voucher_type['base_type'] == '2') + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } + $this->template->set('page_title', 'View ' . $current_voucher_type['name'] . ' Voucher');
/* Load current voucher details */ diff --git a/system/application/models/ledger_model.php b/system/application/models/ledger_model.php index e152bb0..aa6291b 100644 --- a/system/application/models/ledger_model.php +++ b/system/application/models/ledger_model.php @@ -128,7 +128,7 @@ class Ledger_model extends Model { $current_voucher_type = voucher_type_info($voucher_type_id); $ledger_type = 'C';
- if ($current_voucher_type['bank_cash_ledger_restriction'] == 3) + if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') $ledger_type = 'D';
$this->db->select('ledgers.name as name'); @@ -141,9 +141,15 @@ class Ledger_model extends Model { $ledger_multiple = ($ledger_q->num_rows() > 1) ? TRUE : FALSE; $html = ''; if ($ledger_multiple) - $html .= anchor('voucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "(" . $ledger->name . ")", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); + if ($current_voucher_type['base_type'] == '1') + $html .= anchor('voucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "(" . $ledger->name . ")", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); + else + $html .= anchor('inventory/stockvoucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, "(" . $ledger->name . ")", array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); else - $html .= anchor('voucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, $ledger->name, array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); + if ($current_voucher_type['base_type'] == '1') + $html .= anchor('voucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, $ledger->name, array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); + else + $html .= anchor('inventory/stockvoucher/view/' . $current_voucher_type['label'] . "/" . $voucher_id, $ledger->name, array('title' => 'View ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'anchor-link-a')); return $html; } return; diff --git a/system/application/views/inventory/stockvoucher/downloadpreview.php b/system/application/views/inventory/stockvoucher/downloadpreview.php new file mode 100644 index 0000000..52ee803 --- /dev/null +++ b/system/application/views/inventory/stockvoucher/downloadpreview.php @@ -0,0 +1,165 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<title><?php $current_voucher_type['name']; ?> Voucher Number <?php echo $voucher_number; ?></title> + +<style type="text/css"> + body { + color:#000000; + font:14px "Helvetica Neue","Lucida Grande","Helvetica Neue",Arial,sans-serif; + margin:20px; + padding:0; + } + + #print-account-name { + text-align:center; + font-size:17px; + } + + #print-account-address { + text-align:center; + font-size:14px; + } + + #print-voucher-type { + text-align:center; + font-size:15px; + } + + table.print-voucher-table { + border:1px solid #000000; + border-collapse: collapse; + } + + table.print-voucher-table tr.tr-title { + text-align:left; + border:1px solid #000000; + padding:5px 0 5px 2px; + } + + table.print-voucher-table tr.tr-title th { + padding:5px 0 5px 5px; + } + + table.print-voucher-table td { + padding:5px 0 5px 5px; + } + + table.print-voucher-table td.item { + padding-right:35px; + } + + table.print-voucher-table td.last-item { + padding-right:5px; + } + + table.print-voucher-table tr.tr-total { + border:1px solid #000000; + } +</style> + +</head> +<body> + <div id="print-account-name"><span class="value"><?php echo $this->config->item('account_name'); ?></span></div> + <div id="print-account-address"><span class="value"><?php echo $this->config->item('account_address'); ?></span></div> + <br /> + <div id="print-voucher-type"><span class="value"><?php echo $current_voucher_type['name']; ?> Voucher</span></div> + <br /> + <div id="print-voucher-number"><?php echo $current_voucher_type['name']; ?> Voucher Number : <span class="value"><?php echo full_voucher_number($voucher_type_id, $cur_voucher->number); ?></span></div> + <div id="print-voucher-number"><?php echo $current_voucher_type['name']; ?> Voucher Date : <span class="value"><?php echo date_mysql_to_php_display($cur_voucher->date); ?></span></div> + <br /> + + <table class="print-voucher-table"> + <tr> + <td align="right"> + <?php + if ($current_voucher_type['stock_voucher_type'] == '1') + echo "Purchase Ledger A/C :"; + else + echo "Sale Ledger A/C :"; + ?> + </td> + <td class="last-item"> + <?php + $main_account = $cur_voucher_main_account->row(); + echo "<span class=\"bold\">" . $this->Ledger_model->get_name($main_account->ledger_id) . "</span>"; + ?> + </td> + </tr> + <tr> + <td align="right"> + <?php + if ($current_voucher_type['stock_voucher_type'] == '1') + echo "Creditor (Supplier) :"; + else + echo "Debtor (Customer) :"; + ?> + </td> + <td class="last-item"> + <?php + $main_entity = $cur_voucher_main_entity->row(); + echo "<span class=\"bold\">" . $this->Ledger_model->get_name($main_entity->ledger_id) . "</span>"; + ?> + </td> + </tr> + </table> + + <br /> + + <table class="print-voucher-table"> + <thead> + <tr class="tr-title"><th>Stock Item</th><th>Quantity</th><th>Rate</th><th>Discount</th><th>Total</th></tr> + </thead> + <tbody> + <?php + foreach ($cur_voucher_stock_items->result() as $row) + { + echo "<tr class=\"tr-stock-item\">"; + echo "<td class=\"item\">" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td class=\"item\">" . $row->quantity . "</td>"; + echo "<td class=\"item\">" . $row->rate_per_unit . "</td>"; + echo "<td class=\"item\">" . $row->discount . "</td>"; + echo "<td class=\"last-item\">" . $row->total . "</td>"; + echo "</tr>"; + } + ?> + </tbody> + </table> + + <br /> + + <table class="print-voucher-table"> + <thead> + <tr class="tr-title"><th>Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr> + </thead> + <tbody> + <?php + $currency = $this->config->item('account_currency_symbol'); + foreach ($cur_voucher_ledgers->result() as $row) + { + echo "<tr class=\"tr-ledger\">"; + if ($row->dc == "D") + { + echo "<td class=\"ledger-name item\">Dr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; + } else { + echo "<td class=\"ledger-name item\">Cr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; + } + if ($row->dc == "D") + { + echo "<td class=\"ledger-dr item\">" . $currency . " " . $row->amount . "</td>"; + echo "<td class=\"ledger-cr last-item\"></td>"; + } else { + echo "<td class=\"ledger-dr item\"></td>"; + echo "<td class=\"ledger-cr last-item\">" . $currency . " " . $row->amount . "</td>"; + } + echo "</tr>"; + } + echo "<tr class=\"tr-total\"><td class=\"total-name\">Total</td><td class=\"total-dr\">" . $currency . " " . $cur_voucher->dr_total . "</td><td class=\"total-cr\">" . $currency . " " . $cur_voucher->cr_total . "</td></tr>"; + ?> + </tbody> + </table> + <br /> + <div id="print-voucher-narration">Narration : <span class="value"><?php echo $cur_voucher->narration; ?></span></div> + <br /> +</body> +</html> diff --git a/system/application/views/inventory/stockvoucher/email.php b/system/application/views/inventory/stockvoucher/email.php new file mode 100644 index 0000000..1cac7c1 --- /dev/null +++ b/system/application/views/inventory/stockvoucher/email.php @@ -0,0 +1,54 @@ +<style type="text/css"> +#error-box { + border:solid 1px #C34A2C; + background:#FFBABA; + color:#222222; + padding:0 10px 0 10px; + margin:0 0 10px 0; + text-align:left; +} + +#message-box { + border:solid 1px #FFEC8B; + background:#FFF8C6; + color:#222222; + padding:0 10px 0 10px; + margin:0 0 10px 0; + text-align:left; +} +</style> +<?php + if (isset($error) && $error) + { + echo "<div id=\"error-box\">"; + echo "<ul>"; + echo ($error); + echo "</ul>"; + echo "</div>"; + } + + if (isset($message) && $message) + { + echo "<div id=\"message-box\">"; + echo "<ul>"; + echo ($message); + echo "</ul>"; + echo "</div>"; + } + + echo form_open('inventory/stockvoucher/email/' . $current_voucher_type['label'] . "/" . $voucher_id); + + echo "Emailing " . $current_voucher_type['name'] . " Voucher No. " . $voucher_number . "<br />"; + + echo "<p>"; + echo form_label('Email to', 'email_to'); + echo "<br />"; + echo form_input($email_to); + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Send Email'); + echo "</p>"; + + echo form_close(); + diff --git a/system/application/views/inventory/stockvoucher/emailpreview.php b/system/application/views/inventory/stockvoucher/emailpreview.php new file mode 100644 index 0000000..a1f0bcc --- /dev/null +++ b/system/application/views/inventory/stockvoucher/emailpreview.php @@ -0,0 +1,106 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<title>Email - <?php echo $current_voucher_type['name']; ?> Voucher Number <?php echo full_voucher_number($voucher_type_id, $cur_voucher->number); ?></title> +</head> +<body> + <p><?php echo $this->config->item('account_name'); ?></p> + <p><?php echo $this->config->item('account_address'); ?></p> + <p><strong><?php echo $current_voucher_type['name']; ?> Voucher</strong></p> + <p><?php echo $current_voucher_type['name']; ?> Voucher Number : <strong><?php echo full_voucher_number($voucher_type_id, $cur_voucher->number); ?></strong></p> + <p><?php echo $current_voucher_type['name']; ?> Voucher Date : <strong><?php echo date_mysql_to_php_display($cur_voucher->date); ?></strong></p> + + <table border=1 cellpadding=6> + <tr> + <td align="right"> + <?php + if ($current_voucher_type['stock_voucher_type'] == '1') + echo "Purchase Ledger A/C :"; + else + echo "Sale Ledger A/C :"; + ?> + </td> + <td> + <?php + $main_account = $cur_voucher_main_account->row(); + echo "<span class=\"bold\">" . $this->Ledger_model->get_name($main_account->ledger_id) . "</span>"; + ?> + </td> + </tr> + <tr> + <td align="right"> + <?php + if ($current_voucher_type['stock_voucher_type'] == '1') + echo "Creditor (Supplier) :"; + else + echo "Debtor (Customer) :"; + ?> + </td> + <td> + <?php + $main_entity = $cur_voucher_main_entity->row(); + echo "<span class=\"bold\">" . $this->Ledger_model->get_name($main_entity->ledger_id) . "</span>"; + ?> + </td> + </tr> + </table> + + <br /> + + <table border=1 cellpadding=6> + <thead> + <tr><th align="left">Stock Item</th><th>Quantity</th><th>Rate</th><th>Discount</th><th>Total</th></tr> + </thead> + <tbody> + <?php + foreach ($cur_voucher_stock_items->result() as $row) + { + echo "<tr>"; + echo "<td>" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td>" . $row->quantity . "</td>"; + echo "<td>" . $row->rate_per_unit . "</td>"; + echo "<td>" . $row->discount . "</td>"; + echo "<td>" . $row->total . "</td>"; + echo "</tr>"; + } + ?> + </tbody> + </table> + + <br /> + + <table border=1 cellpadding=6> + <thead> + <tr><th align="left">Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr> + </thead> + <tbody> + <?php + $currency = $this->config->item('account_currency_symbol'); + foreach ($cur_voucher_ledgers->result() as $row) + { + echo "<tr>"; + if ($row->dc == "D") + { + echo "<td>Dr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; + } else { + echo "<td>Cr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; + } + if ($row->dc == "D") + { + echo "<td>" . $currency . " " . $row->amount . "</td>"; + echo "<td></td>"; + } else { + echo "<td></td>"; + echo "<td>" . $currency . " " . $row->amount . "</td>"; + } + echo "</tr>"; + } + echo "<tr><td>Total</td><td>" . $currency . " " . $cur_voucher->dr_total . "</td><td>" . $currency . " " . $cur_voucher->cr_total . "</td></tr>"; + ?> + </tbody> + </table> + <br /> + <p>Narration : <span class="value"><?php echo $cur_voucher->narration; ?></p> + <br /> +</body> +</html> diff --git a/system/application/views/inventory/stockvoucher/printpreview.php b/system/application/views/inventory/stockvoucher/printpreview.php new file mode 100644 index 0000000..a7cd8e1 --- /dev/null +++ b/system/application/views/inventory/stockvoucher/printpreview.php @@ -0,0 +1,114 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<title>Print - <?php echo $current_voucher_type['name']; ?> Voucher Number <?php echo $voucher_number; ?></title> +<?php echo link_tag(asset_url() . 'images/favicon.ico', 'shortcut icon', 'image/ico'); ?> +<link type="text/css" rel="stylesheet" href="<?php echo asset_url(); ?>css/printvoucher.css"> +</head> +<body> + <div id="print-account-name"><span class="value"><?php echo $this->config->item('account_name'); ?></span></div> + <div id="print-account-address"><span class="value"><?php echo $this->config->item('account_address'); ?></span></div> + <br /> + <div id="print-voucher-type"><span class="value"><?php echo $current_voucher_type['name']; ?> Voucher</span></div> + <br /> + <div id="print-voucher-number"><?php echo $current_voucher_type['name']; ?> Voucher Number : <span class="value"><?php echo full_voucher_number($voucher_type_id, $cur_voucher->number); ?></span></div> + <div id="print-voucher-number"><?php echo $current_voucher_type['name']; ?> Voucher Date : <span class="value"><?php echo date_mysql_to_php_display($cur_voucher->date); ?></span></div> + <br /> + + <table id="print-voucher-table"> + <tr> + <td align="right"> + <?php + if ($current_voucher_type['stock_voucher_type'] == '1') + echo "Purchase Ledger A/C"; + else + echo "Sale Ledger A/C"; + ?> + </td> + <td> + <?php + $main_account = $cur_voucher_main_account->row(); + echo "<span class=\"bold\">" . $this->Ledger_model->get_name($main_account->ledger_id) . "</span>"; + ?> + </td> + </tr> + <tr> + <td align="right"> + <?php + if ($current_voucher_type['stock_voucher_type'] == '1') + echo "Creditor (Supplier)"; + else + echo "Debtor (Customer)"; + ?> + </td> + <td> + <?php + $main_entity = $cur_voucher_main_entity->row(); + echo "<span class=\"bold\">" . $this->Ledger_model->get_name($main_entity->ledger_id) . "</span>"; + ?> + </td> + </tr> + </table> + + <br /> + + <table id="print-voucher-table"> + <thead> + <tr class="tr-title"><th>Stock Item</th><th>Quantity</th><th>Rate</th><th>Discount</th><th>Total</th></tr> + </thead> + <tbody> + <?php + foreach ($cur_voucher_stock_items->result() as $row) + { + echo "<tr class=\"tr-stock-item\">"; + echo "<td class=\"item\">" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td class=\"item\">" . $row->quantity . "</td>"; + echo "<td class=\"item\">" . $row->rate_per_unit . "</td>"; + echo "<td class=\"item\">" . $row->discount . "</td>"; + echo "<td class=\"last-item\">" . $row->total . "</td>"; + echo "</tr>"; + } + ?> + </tbody> + </table> + + <br /> + + <table id="print-voucher-table"> + <thead> + <tr class="tr-title"><th>Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr> + </thead> + <tbody> + <?php + $currency = $this->config->item('account_currency_symbol'); + foreach ($cur_voucher_ledgers->result() as $row) + { + echo "<tr class=\"tr-ledger\">"; + if ($row->dc == "D") + { + echo "<td class=\"ledger-name item\">Dr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; + } else { + echo "<td class=\"ledger-name item\">Cr " . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; + } + if ($row->dc == "D") + { + echo "<td class=\"ledger-dr item\">" . $currency . " " . $row->amount . "</td>"; + echo "<td class=\"ledger-cr last-item\"></td>"; + } else { + echo "<td class=\"ledger-dr item\"></td>"; + echo "<td class=\"ledger-cr last-item\">" . $currency . " " . $row->amount . "</td>"; + } + echo "</tr>"; + } + echo "<tr class=\"tr-total\"><td class=\"total-name\">Total</td><td class=\"total-dr\">" . $currency . " " . $cur_voucher->dr_total . "</td><td class=\"total-cr\">" . $currency . " " . $cur_voucher->cr_total . "</td></tr>"; + ?> + </tbody> + </table> + <br /> + <div id="print-voucher-narration">Narration : <span class="value"><?php echo $cur_voucher->narration; ?></span></div> + <br /> + <form> + <input class="hide-print" type="button" onClick="window.print()" value="Print voucher"> + </form> +</body> +</html> diff --git a/system/application/views/inventory/stockvoucher/view.php b/system/application/views/inventory/stockvoucher/view.php new file mode 100644 index 0000000..3bf649d --- /dev/null +++ b/system/application/views/inventory/stockvoucher/view.php @@ -0,0 +1,115 @@ +<p>Voucher Number : <span class="bold"><?php echo full_voucher_number($voucher_type_id, $cur_voucher->number); ?></span> + +Voucher Date : <span class="bold"><?php echo date_mysql_to_php_display($cur_voucher->date); ?></span> +</p> + +<table border=0 cellpadding=2> + <tr> + <td align="right"> + <?php + if ($current_voucher_type['stock_voucher_type'] == '1') + echo "Purchase Ledger A/C :"; + else + echo "Sale Ledger A/C :"; + ?> + </td> + <td> + <?php + $main_account = $cur_voucher_main_account->row(); + echo "<span class=\"bold\">" . $this->Ledger_model->get_name($main_account->ledger_id) . "</span>"; + ?> + </td> + </tr> + <tr> + <td align="right"> + <?php + if ($current_voucher_type['stock_voucher_type'] == '1') + echo "Creditor (Supplier) :"; + else + echo "Debtor (Customer) :"; + ?> + </td> + <td> + <?php + $main_entity = $cur_voucher_main_entity->row(); + echo "<span class=\"bold\">" . $this->Ledger_model->get_name($main_entity->ledger_id) . "</span>"; + ?> + </td> + </tr> +</table> + +<table border=0 cellpadding=5 class="simple-table voucher-view-table"> +<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate</th><th>Discount</th><th>Total</th></tr></thead> +<?php +foreach ($cur_voucher_stock_items->result() as $row) +{ + echo "<tr>"; + echo "<td>" . $this->Stock_Item_model->get_name($row->stock_item_id) . "</td>"; + echo "<td>" . $row->quantity . "</td>"; + echo "<td>" . $row->rate_per_unit . "</td>"; + echo "<td>" . $row->discount . "</td>"; + echo "<td>" . $row->total . "</td>"; + echo "</tr>"; +} +?> +</table> + +<br /> + +<table border=0 cellpadding=5 class="simple-table voucher-view-table"> +<thead><tr><th>Type</th><th>Ledger A/C</th><th>Dr Amount</th><th>Cr Amount</th></tr></thead> +<?php +foreach ($cur_voucher_ledgers->result() as $row) +{ + echo "<tr>"; + echo "<td>" . convert_dc($row->dc) . "</td>"; + echo "<td>" . $this->Ledger_model->get_name($row->ledger_id) . "</td>"; + if ($row->dc == "D") + { + echo "<td>Dr " . $row->amount . "</td>"; + echo "<td></td>"; + } else { + echo "<td></td>"; + echo "<td>Cr " . $row->amount . "</td>"; + } + echo "</tr>"; +} +?> +<tr class="voucher-total"><td colspan=2><strong>Total</strong></td><td id=dr-total>Dr <?php echo $cur_voucher->dr_total; ?></td><td id=cr-total">Cr <?php echo $cur_voucher->cr_total; ?></td></tr> +<?php +if ($cur_voucher->dr_total != $cur_voucher->cr_total) +{ + $difference = $cur_voucher->dr_total - $cur_voucher->cr_total; + if ($difference < 0) + echo "<tr class=\"voucher-difference\"><td colspan=2><strong>Difference</strong></td><td id=\"dr-diff\"></td><td id=\"cr-diff\">" . convert_amount_dc($difference) . "</td></tr>"; + else + echo "<tr class=\"voucher-difference\"><td colspan=2><strong>Difference</strong></td><td id=\"dr-diff\">" . convert_amount_dc($difference) . "</td><td id=\"cr-diff\"></td></tr>"; +} +?> +</table> +<p>Narration :<br /> +<span class="bold"><?php echo $cur_voucher->narration; ?></span> +</p> +<p> +Tag : +<?php +$cur_voucher_tag = $this->Tag_model->show_voucher_tag($cur_voucher->tag_id); +if ($cur_voucher_tag == "") + echo "(None)"; +else + echo $cur_voucher_tag; +?> +</p> +<?php + echo anchor('voucher/show/' . $current_voucher_type['label'], 'Back', array('title' => 'Back to ' . $current_voucher_type['name'] . ' Vouchers')); + echo " | "; + echo anchor('inventory/stockvoucher/edit/' . $current_voucher_type['label'] . "/" . $cur_voucher->id, 'Edit', array('title' => 'Edit ' . $current_voucher_type['name'] . ' Voucher')); + echo " | "; + echo anchor('inventory/stockvoucher/delete/' . $current_voucher_type['label'] . "/" . $cur_voucher->id, 'Delete', array('class' => "confirmClick", 'title' => "Delete voucher", 'title' => 'Delete this ' . $current_voucher_type['name'] . ' Voucher')); + echo " | "; + echo anchor_popup('inventory/stockvoucher/printpreview/' . $current_voucher_type['label'] . "/" . $cur_voucher->id, 'Print', array('title' => 'Print this ' . $current_voucher_type['name'] . ' Voucher', 'width' => '600', 'height' => '600')); + echo " | "; + echo anchor_popup('inventory/stockvoucher/email/' . $current_voucher_type['label'] . "/" . $cur_voucher->id, 'Email', array('title' => 'Email this ' . $current_voucher_type['name'] . ' Voucher', 'width' => '400', 'height' => '200')); + echo " | "; + echo anchor('inventory/stockvoucher/download/' . $current_voucher_type['label'] . "/" . $cur_voucher->id, 'Download', array('title' => "Download voucher", 'title' => 'Download this ' . $current_voucher_type['name'] . ' Voucher')); + diff --git a/system/application/views/voucher/view.php b/system/application/views/voucher/view.php index 39ff524..15e3f7d 100644 --- a/system/application/views/voucher/view.php +++ b/system/application/views/voucher/view.php @@ -30,9 +30,9 @@ if ($cur_voucher->dr_total != $cur_voucher->cr_total) { $difference = $cur_voucher->dr_total - $cur_voucher->cr_total; if ($difference < 0) - echo "<tr class=\"voucher-difference\"><td colspan=2><strong>Difference</strong></td><td id=\"dr-diff\"></td><td id=\"cr-diff\">" . $cur_voucher->cr_total . "</td></tr>"; + echo "<tr class=\"voucher-difference\"><td colspan=2><strong>Difference</strong></td><td id=\"dr-diff\"></td><td id=\"cr-diff\">" . convert_amount_dc($difference) . "</td></tr>"; else - echo "<tr class=\"voucher-difference\"><td colspan=2><strong>Difference</strong></td><td id=\"dr-diff\">" . $cur_voucher->dr_total . "</td><td id=\"cr-diff\"></td></tr>"; + echo "<tr class=\"voucher-difference\"><td colspan=2><strong>Difference</strong></td><td id=\"dr-diff\">" . convert_amount_dc($difference) . "</td><td id=\"cr-diff\"></td></tr>"; } ?> </table>
commit 989df69bd800ee93804668cffbc1a9c28c6af7cf Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sun Feb 13 18:59:39 2011 +0530
Updated voucher types add/edit to show relevant options
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/views/setting/vouchertypes/add.php b/system/application/views/setting/vouchertypes/add.php index d3f81aa..cb87bd6 100644 --- a/system/application/views/setting/vouchertypes/add.php +++ b/system/application/views/setting/vouchertypes/add.php @@ -1,3 +1,22 @@ +<script type="text/javascript"> +$(document).ready(function() { + $('#voucher_type_base_type').change(function() { + if ($(this).val() == "1") { + $('#bank_cash_ledger_restriction').show(); + $('#stock_voucher_type').hide(); + } else if ($(this).val() == "2") { + $('#bank_cash_ledger_restriction').hide(); + $('#stock_voucher_type').show(); + } else { + $('#bank_cash_ledger_restriction').show(); + $('#stock_voucher_type').show(); + } + }); + /* initialize */ + $('#voucher_type_base_type').trigger('change'); +}); +</script> + <?php echo form_open('setting/vouchertypes/add');
@@ -24,16 +43,16 @@ echo "<p>"; echo form_label('Base Type', 'voucher_type_base_type'); echo "<br />"; - echo form_dropdown('voucher_type_base_type', $voucher_type_base_types, $voucher_type_base_type_active); + echo form_dropdown('voucher_type_base_type', $voucher_type_base_types, $voucher_type_base_type_active, 'id="voucher_type_base_type"'); echo "</p>";
- echo "<p>"; + echo "<p id="bank_cash_ledger_restriction">"; echo form_label('Restrictions', 'bank_cash_ledger_restriction'); echo "<br />"; echo form_dropdown('bank_cash_ledger_restriction', $bank_cash_ledger_restrictions, $bank_cash_ledger_restriction_active); echo "</p>";
- echo "<p>"; + echo "<p id="stock_voucher_type">"; echo form_label('Stock Voucher Type', 'stock_voucher_type'); echo "<br />"; echo form_dropdown('stock_voucher_type', $stock_voucher_types, $stock_voucher_type_active); diff --git a/system/application/views/setting/vouchertypes/edit.php b/system/application/views/setting/vouchertypes/edit.php index fa16410..a2eadfd 100644 --- a/system/application/views/setting/vouchertypes/edit.php +++ b/system/application/views/setting/vouchertypes/edit.php @@ -1,3 +1,22 @@ +<script type="text/javascript"> +$(document).ready(function() { + $('#voucher_type_base_type').change(function() { + if ($(this).val() == "1") { + $('#bank_cash_ledger_restriction').show(); + $('#stock_voucher_type').hide(); + } else if ($(this).val() == "2") { + $('#bank_cash_ledger_restriction').hide(); + $('#stock_voucher_type').show(); + } else { + $('#bank_cash_ledger_restriction').show(); + $('#stock_voucher_type').show(); + } + }); + /* initialize */ + $('#voucher_type_base_type').trigger('change'); +}); +</script> + <?php echo form_open('setting/vouchertypes/edit/' . $voucher_type_id);
@@ -24,16 +43,16 @@ echo "<p>"; echo form_label('Base Type', 'voucher_type_base_type'); echo "<br />"; - echo form_dropdown('voucher_type_base_type', $voucher_type_base_types, $voucher_type_base_type_active); + echo form_dropdown('voucher_type_base_type', $voucher_type_base_types, $voucher_type_base_type_active, 'id="voucher_type_base_type"'); echo "</p>";
- echo "<p>"; + echo "<p id="bank_cash_ledger_restriction">"; echo form_label('Restrictions', 'bank_cash_ledger_restriction'); echo "<br />"; echo form_dropdown('bank_cash_ledger_restriction', $bank_cash_ledger_restrictions, $bank_cash_ledger_restriction_active); echo "</p>";
- echo "<p>"; + echo "<p id="stock_voucher_type">"; echo form_label('Stock Voucher Type', 'stock_voucher_type'); echo "<br />"; echo form_dropdown('stock_voucher_type', $stock_voucher_types, $stock_voucher_type_active);
commit c400108384a95fd899ca62fd25fe861bdd29b079 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sun Feb 13 15:14:18 2011 +0530
Updated Ledger A/C add/edit to show only relevant options
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/views/ledger/add.php b/system/application/views/ledger/add.php index d597041..bd1fa38 100644 --- a/system/application/views/ledger/add.php +++ b/system/application/views/ledger/add.php @@ -1,3 +1,30 @@ +<script type="text/javascript"> +$(document).ready(function() { + /* initialize */ + if ($('#affects_inventory').attr("checked") == true) + $('#ledger_type_cashbank').attr("checked", false); + else + $('#affects_inventory_option').hide(); + if ($('#ledger_type_cashbank').attr("checked") == true) + $('#affects_inventory').attr("checked", false); + + $('#ledger_type_cashbank').click(function() { + if (this.checked == true) { + $('#affects_inventory').attr("checked", false); + $('#affects_inventory_option').fadeOut(); + } + }); + $('#affects_inventory').click(function() { + if (this.checked == true) { + $('#ledger_type_cashbank').attr("checked", false); + $('#affects_inventory_option').fadeIn(); + } else { + $('#affects_inventory_option').fadeOut(); + } + }); +}); +</script> + <?php echo form_open('ledger/add');
@@ -26,14 +53,14 @@
echo "<p>"; echo "<span id="tooltip-target-2">"; - echo form_checkbox('ledger_type_cashbank', 1, $ledger_type_cashbank) . " Bank or Cash Account"; + echo form_checkbox('ledger_type_cashbank', 1, $ledger_type_cashbank, 'id="ledger_type_cashbank"') . " Bank or Cash Account"; echo "</span>"; echo "<span id="tooltip-content-2">Select if Ledger A/C is a Bank A/C or a Cash A/C.</span>"; echo "</p>";
echo "<p>"; - echo form_checkbox('affects_inventory', 1, $affects_inventory) . " Affects Inventory "; - echo form_dropdown('affects_inventory_option', $affects_inventory_options, $affects_inventory_option_active); + echo form_checkbox('affects_inventory', 1, $affects_inventory, 'id="affects_inventory"') . " Affects Inventory "; + echo form_dropdown('affects_inventory_option', $affects_inventory_options, $affects_inventory_option_active, 'id="affects_inventory_option"'); echo "</p>";
echo "<p>"; diff --git a/system/application/views/ledger/edit.php b/system/application/views/ledger/edit.php index 2801dcd..abf2e49 100644 --- a/system/application/views/ledger/edit.php +++ b/system/application/views/ledger/edit.php @@ -1,3 +1,29 @@ +<script type="text/javascript"> +$(document).ready(function() { + /* initialize */ + if ($('#affects_inventory').attr("checked") == true) + $('#ledger_type_cashbank').attr("checked", false); + else + $('#affects_inventory_option').hide(); + if ($('#ledger_type_cashbank').attr("checked") == true) + $('#affects_inventory').attr("checked", false); + + $('#ledger_type_cashbank').click(function() { + if (this.checked == true) { + $('#affects_inventory').attr("checked", false); + $('#affects_inventory_option').fadeOut(); + } + }); + $('#affects_inventory').click(function() { + if (this.checked == true) { + $('#ledger_type_cashbank').attr("checked", false); + $('#affects_inventory_option').fadeIn(); + } else { + $('#affects_inventory_option').fadeOut(); + } + }); +}); +</script> <?php echo form_open('ledger/edit/' . $ledger_id);
@@ -26,14 +52,14 @@
echo "<p>"; echo "<span id="tooltip-target-2">"; - echo form_checkbox('ledger_type_cashbank', 1, $ledger_type_cashbank) . " Bank or Cash Account"; + echo form_checkbox('ledger_type_cashbank', 1, $ledger_type_cashbank, 'id="ledger_type_cashbank"') . " Bank or Cash Account"; echo "</span>"; echo "<span id="tooltip-content-2">Select if Ledger A/C is a Bank A/C or a Cash A/C.</span>"; echo "</p>";
echo "<p>"; - echo form_checkbox('affects_inventory', 1, $affects_inventory) . " Affects Inventory "; - echo form_dropdown('affects_inventory_option', $affects_inventory_options, $affects_inventory_option_active); + echo form_checkbox('affects_inventory', 1, $affects_inventory, 'id="affects_inventory"') . " Affects Inventory "; + echo form_dropdown('affects_inventory_option', $affects_inventory_options, $affects_inventory_option_active, 'id="affects_inventory_option"'); echo "</p>";
echo "<p>";
commit 3b72cceeb3c587777a0ab98f87fd8c3025e7903e Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sat Feb 12 15:57:42 2011 +0530
Updated stock voucher links to inventory/stockvoucher
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index 02bdfe6..9585ca2 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -522,6 +522,7 @@ class StockVoucher extends Controller { $this->session->set_userdata('voucher_added_type_id', $voucher_type_id); $this->session->set_userdata('voucher_added_type_label', $current_voucher_type['label']); $this->session->set_userdata('voucher_added_type_name', $current_voucher_type['name']); + $this->session->set_userdata('voucher_added_type_base_type', $current_voucher_type['base_type']); $this->session->set_userdata('voucher_added_number', $data_number);
/* Showing success message in show() method since message is too long for storing it in session */ diff --git a/system/application/controllers/voucher.php b/system/application/controllers/voucher.php index eda8357..eeb24af 100644 --- a/system/application/controllers/voucher.php +++ b/system/application/controllers/voucher.php @@ -128,14 +128,24 @@ class Voucher extends Controller { $voucher_added_type_id_temp = $this->session->userdata('voucher_added_type_id'); $voucher_added_type_label_temp = $this->session->userdata('voucher_added_type_label'); $voucher_added_type_name_temp = $this->session->userdata('voucher_added_type_name'); + $voucher_added_type_base_type_temp = $this->session->userdata('voucher_added_type_base_type'); $voucher_added_number_temp = $this->session->userdata('voucher_added_number'); $voucher_added_message = 'Added ' . $voucher_added_type_name_temp . ' Voucher number ' . full_voucher_number($voucher_added_type_id_temp, $voucher_added_number_temp) . "."; $voucher_added_message .= " You can [ "; - $voucher_added_message .= anchor('voucher/view/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'View', array('class' => 'anchor-link-a')) . " | "; - $voucher_added_message .= anchor('voucher/edit/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'Edit', array('class' => 'anchor-link-a')) . " | "; - $voucher_added_message .= anchor_popup('voucher/printpreview/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp , 'Print', array('class' => 'anchor-link-a', 'width' => '600', 'height' => '600')) . " | "; - $voucher_added_message .= anchor_popup('voucher/email/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'Email', array('class' => 'anchor-link-a', 'width' => '500', 'height' => '300')) . " | "; - $voucher_added_message .= anchor('voucher/download/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'Download', array('class' => 'anchor-link-a')); + if ($voucher_added_type_base_type_temp == '1') + { + $voucher_added_message .= anchor('voucher/view/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'View', array('class' => 'anchor-link-a')) . " | "; + $voucher_added_message .= anchor('voucher/edit/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'Edit', array('class' => 'anchor-link-a')) . " | "; + $voucher_added_message .= anchor_popup('voucher/printpreview/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp , 'Print', array('class' => 'anchor-link-a', 'width' => '600', 'height' => '600')) . " | "; + $voucher_added_message .= anchor_popup('voucher/email/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'Email', array('class' => 'anchor-link-a', 'width' => '500', 'height' => '300')) . " | "; + $voucher_added_message .= anchor('voucher/download/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'Download', array('class' => 'anchor-link-a')); + } else { + $voucher_added_message .= anchor('inventory/stockvoucher/view/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'View', array('class' => 'anchor-link-a')) . " | "; + $voucher_added_message .= anchor('inventory/stockvoucher/edit/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'Edit', array('class' => 'anchor-link-a')) . " | "; + $voucher_added_message .= anchor_popup('inventory/stockvoucher/printpreview/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp , 'Print', array('class' => 'anchor-link-a', 'width' => '600', 'height' => '600')) . " | "; + $voucher_added_message .= anchor_popup('inventory/stockvoucher/email/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'Email', array('class' => 'anchor-link-a', 'width' => '500', 'height' => '300')) . " | "; + $voucher_added_message .= anchor('inventory/stockvoucher/download/' . $voucher_added_type_label_temp . "/" . $voucher_added_id_temp, 'Download', array('class' => 'anchor-link-a')); + } $voucher_added_message .= " ] it."; $this->messages->add($voucher_added_message, 'success'); $this->session->unset_userdata('voucher_added_show_action'); @@ -143,6 +153,7 @@ class Voucher extends Controller { $this->session->unset_userdata('voucher_added_type_id'); $this->session->unset_userdata('voucher_added_type_label'); $this->session->unset_userdata('voucher_added_type_name'); + $this->session->unset_userdata('voucher_added_type_base_type'); $this->session->unset_userdata('voucher_added_number'); }
@@ -546,6 +557,7 @@ class Voucher extends Controller { $this->session->set_userdata('voucher_added_type_id', $voucher_type_id); $this->session->set_userdata('voucher_added_type_label', $current_voucher_type['label']); $this->session->set_userdata('voucher_added_type_name', $current_voucher_type['name']); + $this->session->set_userdata('voucher_added_type_base_type', $current_voucher_type['base_type']); $this->session->set_userdata('voucher_added_number', $data_number);
/* Showing success message in show() method since message is too long for storing it in session */ diff --git a/system/application/views/voucher/index.php b/system/application/views/voucher/index.php index fee5836..3285cf5 100644 --- a/system/application/views/voucher/index.php +++ b/system/application/views/voucher/index.php @@ -34,11 +34,20 @@ echo "<td>" . $row->dr_total . "</td>"; echo "<td>" . $row->cr_total . "</td>";
- echo "<td>" . anchor('voucher/edit/' . $current_voucher_type['label'] . "/" . $row->id , "Edit", array('title' => 'Edit ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'red-link')) . " "; - echo " " . anchor('voucher/delete/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Delete ' . $current_voucher_type['name'] . ' Voucher', 'class' => "confirmClick", 'title' => "Delete voucher")), array('title' => 'Delete ' . $current_voucher_type['name'] . ' Voucher')) . " "; - echo " " . anchor_popup('voucher/printpreview/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/print.png", 'border' => '0', 'alt' => 'Print ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Print ' . $current_voucher_type['name']. ' Voucher', 'width' => '600', 'height' => '600')) . " "; - echo " " . anchor_popup('voucher/email/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/email.png", 'border' => '0', 'alt' => 'Email ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Email ' . $current_voucher_type['name'] . ' Voucher', 'width' => '500', 'height' => '300')) . " "; - echo " " . anchor('voucher/download/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/save.png", 'border' => '0', 'alt' => 'Download ' . $current_voucher_type['name'] . ' Voucher', 'title' => "Download voucher")), array('title' => 'Download ' . $current_voucher_type['name'] . ' Voucher')) . "</td>"; + if ($current_voucher_type['base_type'] == '1') + { + echo "<td>" . anchor('voucher/edit/' . $current_voucher_type['label'] . "/" . $row->id , "Edit", array('title' => 'Edit ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'red-link')) . " "; + echo " " . anchor('voucher/delete/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Delete ' . $current_voucher_type['name'] . ' Voucher', 'class' => "confirmClick", 'title' => "Delete voucher")), array('title' => 'Delete ' . $current_voucher_type['name'] . ' Voucher')) . " "; + echo " " . anchor_popup('voucher/printpreview/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/print.png", 'border' => '0', 'alt' => 'Print ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Print ' . $current_voucher_type['name']. ' Voucher', 'width' => '600', 'height' => '600')) . " "; + echo " " . anchor_popup('voucher/email/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/email.png", 'border' => '0', 'alt' => 'Email ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Email ' . $current_voucher_type['name'] . ' Voucher', 'width' => '500', 'height' => '300')) . " "; + echo " " . anchor('voucher/download/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/save.png", 'border' => '0', 'alt' => 'Download ' . $current_voucher_type['name'] . ' Voucher', 'title' => "Download voucher")), array('title' => 'Download ' . $current_voucher_type['name'] . ' Voucher')) . "</td>"; + } else { + echo "<td>" . anchor('inventory/stockvoucher/edit/' . $current_voucher_type['label'] . "/" . $row->id , "Edit", array('title' => 'Edit ' . $current_voucher_type['name'] . ' Voucher', 'class' => 'red-link')) . " "; + echo " " . anchor('inventory/stockvoucher/delete/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Delete ' . $current_voucher_type['name'] . ' Voucher', 'class' => "confirmClick", 'title' => "Delete voucher")), array('title' => 'Delete ' . $current_voucher_type['name'] . ' Voucher')) . " "; + echo " " . anchor_popup('inventory/stockvoucher/printpreview/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/print.png", 'border' => '0', 'alt' => 'Print ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Print ' . $current_voucher_type['name']. ' Voucher', 'width' => '600', 'height' => '600')) . " "; + echo " " . anchor_popup('inventory/stockvoucher/email/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/email.png", 'border' => '0', 'alt' => 'Email ' . $current_voucher_type['name'] . ' Voucher')), array('title' => 'Email ' . $current_voucher_type['name'] . ' Voucher', 'width' => '500', 'height' => '300')) . " "; + echo " " . anchor('inventory/stockvoucher/download/' . $current_voucher_type['label'] . "/" . $row->id , img(array('src' => asset_url() . "images/icons/save.png", 'border' => '0', 'alt' => 'Download ' . $current_voucher_type['name'] . ' Voucher', 'title' => "Download voucher")), array('title' => 'Download ' . $current_voucher_type['name'] . ' Voucher')) . "</td>"; + }
echo "</tr>"; }
commit 441e1696a1611fbfa3b2f918d82f34642b03e5dd Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sat Feb 12 15:41:51 2011 +0530
Updated add stock voucher
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/db-update.txt b/db-update.txt index 0561c99..816fa11 100644 --- a/db-update.txt +++ b/db-update.txt @@ -36,6 +36,17 @@ CREATE TABLE IF NOT EXISTS stock_items ( PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
+CREATE TABLE IF NOT EXISTS stock_voucher_items ( + id int(11) NOT NULL AUTO_INCREMENT, + voucher_id int(11) NOT NULL, + stock_item_id int(11) NOT NULL, + quantity float NOT NULL, + rate_per_unit decimal(15,2) NOT NULL DEFAULT '0.00', + discount varchar(15) NOT NULL, + total decimal(15,2) NOT NULL DEFAULT '0.00', + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; + //--------------------------------- VERSION 3 ----------------------------------
CREATE TABLE IF NOT EXISTS voucher_types ( diff --git a/system/application/controllers/admin/schema.sql b/system/application/controllers/admin/schema.sql index ca914a3..98a91aa 100644 --- a/system/application/controllers/admin/schema.sql +++ b/system/application/controllers/admin/schema.sql @@ -132,6 +132,7 @@ CREATE TABLE IF NOT EXISTS stock_items (
CREATE TABLE IF NOT EXISTS stock_voucher_items ( id int(11) NOT NULL AUTO_INCREMENT, + voucher_id int(11) NOT NULL, stock_item_id int(11) NOT NULL, quantity float NOT NULL, rate_per_unit decimal(15,2) NOT NULL DEFAULT '0.00', diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index 892c9fe..02bdfe6 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -211,6 +211,8 @@ class StockVoucher extends Controller { $data_all_rate_item = $this->input->post('rate_item', TRUE); $data_all_amount_item = $this->input->post('amount_item', TRUE);
+ $data_total_amount = 0; + /* Checking for Valid Stock Ledger A/C - account */ if ($current_voucher_type['stock_voucher_type'] == '1') $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 2); @@ -228,9 +230,9 @@ class StockVoucher extends Controller { } /* Checking for Valid Stock Ledger A/C - entity */ if ($current_voucher_type['stock_voucher_type'] == '1') - $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 4); + $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 4)->or_where('type', 1); else - $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 5); + $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 5)->or_where('type', 1); $valid_main_account_q = $this->db->get(); if ($valid_main_account_q->num_rows() < 1) { @@ -309,6 +311,7 @@ class StockVoucher extends Controller { $data_total_amount = 0; $voucher_id = NULL;
+ /* Adding Voucher */ $this->db->trans_start(); $insert_data = array( 'number' => $data_number, @@ -344,20 +347,22 @@ class StockVoucher extends Controller { $this->db->trans_rollback(); if ($current_voucher_type['stock_voucher_type'] == '1') { - $this->messages->add('Error adding Purchase Ledger A/C - ' . $data_main_account . ' to Voucher.', 'error'); + $this->messages->add('Error adding Purchase Ledger A/C to Voucher.', 'error'); $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting purchase ledger " . "[id:" . $data_main_account . "]"); } else { - $this->messages->add('Error adding Sale Ledger A/C - ' . $data_main_account . ' to Voucher.', 'error'); + $this->messages->add('Error adding Sale Ledger A/C to Voucher.', 'error'); $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting sale ledger " . "[id:" . $data_main_account . "]"); } $this->template->load('template', 'inventory/stockvoucher/add', $data); return; + } else { + $main_voucher_id = $this->db->insert_id(); }
/* Adding main - entity */ $insert_data = array( 'voucher_id' => $voucher_id, - 'ledger_id' => $data_entity_account, + 'ledger_id' => $data_main_entity, 'amount' => $data_total_amount, 'dc' => '', ); @@ -370,39 +375,77 @@ class StockVoucher extends Controller { $this->db->trans_rollback(); if ($current_voucher_type['stock_voucher_type'] == '1') { - $this->messages->add('Error adding Creditor (Supplier) - ' . $data_entity_account . ' to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting creditor ledger " . "[id:" . $data_entity_account . "]"); + $this->messages->add('Error adding Creditor (Supplier) to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting creditor ledger " . "[id:" . $data_main_entity . "]"); } else { - $this->messages->add('Error adding Debtor (Customer) - ' . $data_entity_account . ' to Voucher.', 'error'); - $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting debtor ledger " . "[id:" . $data_entity_account . "]"); + $this->messages->add('Error adding Debtor (Customer) - to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting debtor ledger " . "[id:" . $data_main_entity . "]"); } $this->template->load('template', 'inventory/stockvoucher/add', $data); return; + } else { + $entity_voucher_id = $this->db->insert_id(); + } + + /* Adding stock items */ + $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); + $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); + $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); + $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); + $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); + + foreach ($data_all_stock_item_id as $id => $stock_data) + { + $data_stock_item_id = $data_all_stock_item_id[$id]; + + if ($data_stock_item_id < 1) + continue; + + $data_stock_item_quantity = $data_all_stock_item_quantity[$id]; + $data_stock_item_rate_per_unit = $data_all_stock_item_rate_per_unit[$id]; + $data_stock_item_discount = $data_all_stock_item_discount[$id]; + $data_stock_item_amount = $data_all_stock_item_amount[$id]; + + $data_total_amount += $data_stock_item_amount; + + $insert_stock_data = array( + 'voucher_id' => $voucher_id, + 'stock_item_id' => $data_stock_item_id, + 'quantity' => $data_stock_item_quantity, + 'rate_per_unit' => $data_stock_item_rate_per_unit, + 'discount' => $data_stock_item_discount, + 'total' => $data_stock_item_amount, + ); + if ( ! $this->db->insert('stock_voucher_items', $insert_stock_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error adding Stock Item - ' . $data_ledger_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting stock item " . "[id:" . $data_ledger_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } }
/* Adding ledger accounts */ $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); $data_all_ledger_id = $this->input->post('ledger_id', TRUE); - $data_all_dr_amount = $this->input->post('dr_amount', TRUE); - $data_all_cr_amount = $this->input->post('cr_amount', TRUE); + $data_all_rate_item = $this->input->post('rate_item', TRUE); + $data_all_amount_item = $this->input->post('amount_item', TRUE);
- $dr_total = 0; - $cr_total = 0; foreach ($data_all_ledger_dc as $id => $ledger_data) { $data_ledger_dc = $data_all_ledger_dc[$id]; $data_ledger_id = $data_all_ledger_id[$id]; + if ($data_ledger_id < 1) continue; - $data_amount = 0; - if ($data_all_ledger_dc[$id] == "D") - { - $data_amount = $data_all_dr_amount[$id]; - $dr_total += $data_all_dr_amount[$id]; - } else { - $data_amount = $data_all_cr_amount[$id]; - $cr_total += $data_all_cr_amount[$id]; - } + + $data_amount = $data_all_amount_item[$id]; + if ($data_ledger_dc == "D") + $data_total_amount += $data_amount; + else + $data_total_amount -= $data_amount; + $insert_ledger_data = array( 'voucher_id' => $voucher_id, 'ledger_id' => $data_ledger_id, @@ -419,10 +462,10 @@ class StockVoucher extends Controller { } }
- /* Updating Debit and Credit Total in vouchers table */ + /* Updating Debit and Credit Total - vouchers */ $update_data = array( - 'dr_total' => $dr_total, - 'cr_total' => $cr_total, + 'dr_total' => $data_total_amount, + 'cr_total' => $data_total_amount, ); if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) { @@ -433,6 +476,44 @@ class StockVoucher extends Controller { return; }
+ /* Updating Debit and Credit Total - main account */ + $update_data = array( + 'amount' => $data_total_amount, + ); + if ( ! $this->db->where('id', $main_voucher_id)->update('voucher_items', $update_data)) + { + $this->db->trans_rollback(); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->messages->add('Error updating Purchase Ledger A/C total.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating purchase ledger total"); + } else { + $this->messages->add('Error updating Sale Ledger A/C total.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating sale ledger total"); + } + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + + /* Updating Debit and Credit Total - entity account */ + $update_data = array( + 'amount' => $data_total_amount, + ); + if ( ! $this->db->where('id', $entity_voucher_id)->update('voucher_items', $update_data)) + { + $this->db->trans_rollback(); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->messages->add('Error updating Creditor (Supplier) total.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating creditor (supplier) total"); + } else { + $this->messages->add('Error updating Debtor (Customer) total.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debtor (customer) total"); + } + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + /* Success */ $this->db->trans_complete();
@@ -829,7 +910,7 @@ class StockVoucher extends Controller { function delete($voucher_type, $voucher_id = 0) { /* Check access */ - if ( ! check_access('delete voucher')) + if ( ! check_access('delete stock voucher')) { $this->messages->add('Permission denied.', 'error'); redirect('inventory/stockvoucher/show/' . $voucher_type); @@ -864,6 +945,14 @@ class StockVoucher extends Controller { }
$this->db->trans_start(); + if ( ! $this->db->delete('stock_voucher_items', array('voucher_id' => $voucher_id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting Stock Items.', 'error'); + $this->logger->write_message("error", "Error deleting stock item entries for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + redirect('voucher/view/' . $current_voucher_type['label'] . '/' . $voucher_id); + return; + } if ( ! $this->db->delete('voucher_items', array('voucher_id' => $voucher_id))) { $this->db->trans_rollback(); @@ -1146,6 +1235,37 @@ class StockVoucher extends Controller { return; }
+ function addrow() + { + $i = time() + rand (0, time()) + rand (0, time()) + rand (0, time()); + $rate_item = array( + 'name' => 'rate_item[' . $i . ']', + 'id' => 'rate_item[' . $i . ']', + 'maxlength' => '5', + 'size' => '5', + 'value' => isset($dr_amount[$i]) ? $dr_amount[$i] : "", + 'class' => 'dr-item', + ); + $amount_item = array( + 'name' => 'amount_item[' . $i . ']', + 'id' => 'amount_item[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => isset($cr_amount[$i]) ? $cr_amount[$i] : "", + 'class' => 'cr-item', + ); + echo "<tr>"; + echo "<td>" . form_dropdown_dc('ledger_dc[' . $i . ']', 'D') . "</td>"; + echo "<td>" . form_input_ledger('ledger_id[' . $i . ']', '0') . "</td>"; + echo "<td>" . form_input($rate_item) . "</td>"; + echo "<td>" . form_input($amount_item) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addrow')) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deleterow')) . "</td>"; + echo "<td class="ledger-balance"><div></div></td>"; + echo "</tr>"; + return; + } + function addstockrow() { $i = time() + rand (0, time()) + rand (0, time()) + rand (0, time()); diff --git a/system/application/views/inventory/stockvoucher/add.php b/system/application/views/inventory/stockvoucher/add.php index 31c19c1..ef0e6ee 100644 --- a/system/application/views/inventory/stockvoucher/add.php +++ b/system/application/views/inventory/stockvoucher/add.php @@ -1,7 +1,3 @@ -<?php - /* Add row ledger type */ - $add_type = "all"; -?> <script type="text/javascript">
$(document).ready(function() { @@ -47,17 +43,17 @@ $(document).ready(function() { } });
- $('table td .quantity-item').live('change', function() { + $('table td .quantity-stock-item').live('change', function() { var rowid = $(this); calculateRowTotal(rowid.parent().prev()); });
- $('table td .rate-item').live('change', function() { + $('table td .rate-stock-item').live('change', function() { var rowid = $(this); calculateRowTotal(rowid.parent().prev().prev()); });
- $('table td .discount-item').live('change', function() { + $('table td .discount-stock-item').live('change', function() { var rowid = $(this); calculateRowTotal(rowid.parent().prev().prev().prev()); }); @@ -158,10 +154,11 @@ $(document).ready(function() { var add_image_url = $(cur_obj).attr('src'); $(cur_obj).attr('src', <?php echo '\'' . asset_url() . 'images/icons/ajax.gif' . '\''; ?>); $.ajax({ - url: <?php echo '\'' . site_url('voucher/addrow/' . $add_type) . '\''; ?>, + url: <?php echo '\'' . site_url('inventory/stockvoucher/addrow') . '\''; ?>, success: function(data) { $(cur_obj).parent().parent().after(data); $(cur_obj).attr('src', add_image_url); + $('.ledger-dropdown').trigger('change'); } }); }); @@ -251,36 +248,36 @@ $(document).ready(function() { 'id' => 'stock_item_quantity[' . $i . ']', 'maxlength' => '15', 'size' => '9', - 'value' => '', - 'class' => 'quantity-item', + 'value' => isset($stock_item_quantity[$i]) ? $stock_item_quantity[$i] : '', + 'class' => 'quantity-stock-item', ); $stock_item_rate_per_unit = array( 'name' => 'stock_item_rate_per_unit[' . $i . ']', 'id' => 'stock_item_rate_per_unit[' . $i . ']', 'maxlength' => '15', 'size' => '9', - 'value' => '', - 'class' => 'rate-item', + 'value' => isset($stock_item_rate_per_unit[$i]) ? $stock_item_rate_per_unit[$i] : '', + 'class' => 'rate-stock-item', ); $stock_item_discount = array( 'name' => 'stock_item_discount[' . $i . ']', 'id' => 'stock_item_discount[' . $i . ']', 'maxlength' => '15', 'size' => '9', - 'value' => '', - 'class' => 'discount-item', + 'value' => isset($stock_item_discount[$i]) ? $stock_item_discount[$i] : '', + 'class' => 'discount-stock-item', ); $stock_item_amount = array( 'name' => 'stock_item_amount[' . $i . ']', 'id' => 'stock_item_amount[' . $i . ']', 'maxlength' => '15', 'size' => '15', - 'value' => '', - 'class' => 'rate-item', + 'value' => isset($stock_item_amount[$i]) ? $stock_item_amount[$i] : '', + 'class' => 'rate-stock-item', ); echo "<tr>";
- echo "<td>" . form_input_stock_item('stock_item_id[' . $i . ']', 0) . "</td>"; + echo "<td>" . form_input_stock_item('stock_item_id[' . $i . ']', isset($stock_item_id[$i]) ? $stock_item_id[$i] : 0) . "</td>"; echo "<td>" . form_input($stock_item_quantity) . "</td>"; echo "<td>" . form_input($stock_item_rate_per_unit) . "</td>"; echo "<td>" . form_input($stock_item_discount) . "</td>"; @@ -308,23 +305,21 @@ $(document).ready(function() { 'id' => 'rate_item[' . $i . ']', 'maxlength' => '5', 'size' => '5', - 'value' => isset($dr_amount[$i]) ? $dr_amount[$i] : "", - 'class' => 'dr-item', + 'value' => isset($rate_item[$i]) ? $rate_item[$i] : '', + 'class' => 'rate-item', ); $amount_item = array( 'name' => 'amount_item[' . $i . ']', 'id' => 'amount_item[' . $i . ']', 'maxlength' => '15', 'size' => '15', - 'value' => isset($cr_amount[$i]) ? $cr_amount[$i] : "", - 'class' => 'cr-item', + 'value' => isset($amount_item[$i]) ? $amount_item[$i] : '', + 'class' => 'amount-item', ); echo "<tr>";
echo "<td>" . form_dropdown_dc('ledger_dc[' . $i . ']', isset($ledger_dc[$i]) ? $ledger_dc[$i] : "D") . "</td>"; - echo "<td>" . form_input_ledger('ledger_id[' . $i . ']', isset($ledger_id[$i]) ? $ledger_id[$i] : 0) . "</td>"; - echo "<td>" . form_input($rate_item) . "</td>"; echo "<td>" . form_input($amount_item) . "</td>";
commit fd1df2d3239c41cb61f41ea07ed968c7965781ed Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sat Feb 12 13:16:19 2011 +0530
Udpated stock voucher
- Added main ledger and entity ledger - Added seperate puchase and sale voucher type - Added stock voucher items to purchase and sale voucher types - Updated stock vocuher jQuery to updated the total amount for each stock item - Added basic stock validation to stock vouchers
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php index b97aaea..892c9fe 100644 --- a/system/application/controllers/inventory/stockvoucher.php +++ b/system/application/controllers/inventory/stockvoucher.php @@ -107,6 +107,8 @@ class StockVoucher extends Controller { 'rows' => '4', 'value' => '', ); + $data['main_account_active'] = 0; + $data['main_entity_active'] = 0; $data['voucher_type_id'] = $voucher_type_id; $data['current_voucher_type'] = $current_voucher_type; $data['voucher_tags'] = $this->Tag_model->get_all_tags(); @@ -120,16 +122,31 @@ class StockVoucher extends Controller { else $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|is_natural_no_zero|uniquevoucherno[' . $voucher_type_id . ']'); $this->form_validation->set_rules('voucher_date', 'Voucher Date', 'trim|required|is_date|is_date_within_range'); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->form_validation->set_rules('main_account', 'Purchase Ledger A/C', 'trim|required'); + $this->form_validation->set_rules('main_entity', 'Creditors (Supplier)', 'trim|required'); + } else { + $this->form_validation->set_rules('main_account', 'Sale Ledger A/C', 'trim|required'); + $this->form_validation->set_rules('main_entity', 'Debtor (Customer)', 'trim|required'); + } $this->form_validation->set_rules('voucher_narration', 'trim'); $this->form_validation->set_rules('voucher_tag', 'Tag', 'trim|is_natural');
/* Debit and Credit amount validation */ if ($_POST) { + foreach ($this->input->post('stock_item_id', TRUE) as $id => $stock_data) + { + $this->form_validation->set_rules('stock_item_quantity[' . $id . ']', 'Stock Item Quantity', 'trim|quantity'); + $this->form_validation->set_rules('stock_item_rate_per_unit[' . $id . ']', 'Stock Item Rate Per Unit', 'trim|currency'); + $this->form_validation->set_rules('stock_item_discount[' . $id . ']', 'Stock Item Discount', 'trim|rate'); + $this->form_validation->set_rules('stock_item_amount[' . $id . ']', 'Stock Item Amount', 'trim|currency'); + } foreach ($this->input->post('ledger_dc', TRUE) as $id => $ledger_data) { - $this->form_validation->set_rules('dr_amount[' . $id . ']', 'Debit Amount', 'trim|currency'); - $this->form_validation->set_rules('cr_amount[' . $id . ']', 'Credit Amount', 'trim|currency'); + $this->form_validation->set_rules('rate_item[' . $id . ']', 'Rate %', 'trim|rate'); + $this->form_validation->set_rules('amount_item[' . $id . ']', 'Ledger Amount', 'trim|currency'); } }
@@ -141,23 +158,33 @@ class StockVoucher extends Controller { $data['voucher_narration']['value'] = $this->input->post('voucher_narration', TRUE); $data['voucher_tag'] = $this->input->post('voucher_tag', TRUE);
+ $data['main_account_active'] = $this->input->post('main_account', TRUE); + $data['main_entity_active'] = $this->input->post('main_entity', TRUE); + + $data['stock_item_id'] = $this->input->post('stock_item_id', TRUE); + $data['stock_item_quantity'] = $this->input->post('stock_item_quantity', TRUE); + $data['stock_item_rate_per_unit'] = $this->input->post('stock_item_rate_per_unit', TRUE); + $data['stock_item_discount'] = $this->input->post('stock_item_discount', TRUE); + $data['stock_item_amount'] = $this->input->post('stock_item_amount', TRUE); + $data['ledger_dc'] = $this->input->post('ledger_dc', TRUE); $data['ledger_id'] = $this->input->post('ledger_id', TRUE); - $data['dr_amount'] = $this->input->post('dr_amount', TRUE); - $data['cr_amount'] = $this->input->post('cr_amount', TRUE); + $data['rate_item'] = $this->input->post('rate_item', TRUE); + $data['amount_item'] = $this->input->post('amount_item', TRUE); } else { for ($count = 0; $count <= 1; $count++) { $data['ledger_dc'][$count] = "D"; $data['ledger_id'][$count] = 0; - $data['rate'][$count] = ""; - $data['amount'][$count] = ""; + $data['rate_item'][$count] = ""; + $data['amount_item'][$count] = ""; } for ($count = 0; $count <= 3; $count++) { $data['stock_item_id'][$count] = '0'; $data['stock_item_quantity'][$count] = ''; $data['stock_item_rate_per_unit'][$count] = ''; + $data['stock_item_discount'][$count] = ''; $data['stock_item_amount'][$count] = ''; } } @@ -170,109 +197,88 @@ class StockVoucher extends Controller { } else { - /* Checking for Valid Ledgers A/C and Debit and Credit Total */ + $data_main_account = $this->input->post('main_account', TRUE); + $data_main_entity = $this->input->post('main_entity', TRUE); + + $data_all_stock_item_id = $this->input->post('stock_item_id', TRUE); + $data_all_stock_item_quantity = $this->input->post('stock_item_quantity', TRUE); + $data_all_stock_item_rate_per_unit = $this->input->post('stock_item_rate_per_unit', TRUE); + $data_all_stock_item_discount = $this->input->post('stock_item_discount', TRUE); + $data_all_stock_item_amount = $this->input->post('stock_item_amount', TRUE); + $data_all_ledger_id = $this->input->post('ledger_id', TRUE); $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); - $data_all_dr_amount = $this->input->post('dr_amount', TRUE); - $data_all_cr_amount = $this->input->post('cr_amount', TRUE); - $dr_total = 0; - $cr_total = 0; - $bank_cash_present = FALSE; /* Whether atleast one Ledger A/C is Bank or Cash A/C */ - $non_bank_cash_present = FALSE; /* Whether atleast one Ledger A/C is NOT a Bank or Cash A/C */ - foreach ($data_all_ledger_dc as $id => $ledger_data) - { - if ($data_all_ledger_id[$id] < 1) - continue; + $data_all_rate_item = $this->input->post('rate_item', TRUE); + $data_all_amount_item = $this->input->post('amount_item', TRUE);
- /* Check for valid ledger id */ - $this->db->from('ledgers')->where('id', $data_all_ledger_id[$id]); - $valid_ledger_q = $this->db->get(); - if ($valid_ledger_q->num_rows() < 1) - { - $this->messages->add('Invalid Ledger A/C.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } else { - /* Check for valid ledger type */ - $valid_ledger = $valid_ledger_q->row(); - if ($current_voucher_type['bank_cash_ledger_restriction'] == '2') - { - if ($data_all_ledger_dc[$id] == 'D' && $valid_ledger->type == 1) - { - $bank_cash_present = TRUE; - } - if ($valid_ledger->type != 1) - $non_bank_cash_present = TRUE; - } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') - { - if ($data_all_ledger_dc[$id] == 'C' && $valid_ledger->type == 1) - { - $bank_cash_present = TRUE; - } - if ($valid_ledger->type != 1) - $non_bank_cash_present = TRUE; - } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '4') - { - if ($valid_ledger->type != 1) - { - $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers can have only Bank and Cash Ledgers A/C's.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } - } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '5') - { - if ($valid_ledger->type == 1) - { - $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers cannot have Bank and Cash Ledgers A/C's.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } - } - } - - if ($data_all_ledger_dc[$id] == "D") - { - $dr_total += $data_all_dr_amount[$id]; - } else { - $cr_total += $data_all_cr_amount[$id]; - } - } - if ($dr_total != $cr_total) + /* Checking for Valid Stock Ledger A/C - account */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 2); + else + $this->db->from('ledgers')->where('id', $data_main_account)->where('type', 3); + $valid_main_account_q = $this->db->get(); + if ($valid_main_account_q->num_rows() < 1) { - $this->messages->add('Debit and Credit Total does not match!', 'error'); + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->messages->add('Invalid Purchase Ledger A/C.', 'error'); + else + $this->messages->add('Invalid Sale Ledger A/C.', 'error'); $this->template->load('template', 'inventory/stockvoucher/add', $data); return; - } else if ($dr_total == 0 && $cr_total == 0) { - $this->messages->add('Cannot save empty Voucher.', 'error'); + } + /* Checking for Valid Stock Ledger A/C - entity */ + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 4); + else + $this->db->from('ledgers')->where('id', $data_main_entity)->where('type', 5); + $valid_main_account_q = $this->db->get(); + if ($valid_main_account_q->num_rows() < 1) + { + if ($current_voucher_type['stock_voucher_type'] == '1') + $this->messages->add('Invalid Creditor (Supplier).', 'error'); + else + $this->messages->add('Invalid Debtor (Customer).', 'error'); $this->template->load('template', 'inventory/stockvoucher/add', $data); return; } - /* Check if atleast one Bank or Cash Ledger A/C is present */ - if ($current_voucher_type['bank_cash_ledger_restriction'] == '2') + + /* Checking for Valid Stock Item A/C */ + $stock_item_present = FALSE; + foreach ($data_all_stock_item_id as $id => $stock_data) { - if ( ! $bank_cash_present) - { - $this->messages->add('Need to Debit atleast one Bank or Cash A/C.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } - if ( ! $non_bank_cash_present) + if ($data_all_stock_item_id[$id] < 1) + continue; + + /* Check for valid stock item id */ + $this->db->from('stock_items')->where('id', $data_all_stock_item_id[$id]); + $valid_stock_item_q = $this->db->get(); + if ($valid_stock_item_q->num_rows() < 1) { - $this->messages->add('Need to Debit or Credit atleast one NON - Bank or Cash A/C.', 'error'); + $this->messages->add('Invalid Stock Item.', 'error'); $this->template->load('template', 'inventory/stockvoucher/add', $data); return; } - } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') + $stock_item_present = TRUE; + } + if ( ! $stock_item_present) { - if ( ! $bank_cash_present) - { - $this->messages->add('Need to Credit atleast one Bank or Cash A/C.', 'error'); - $this->template->load('template', 'inventory/stockvoucher/add', $data); - return; - } - if ( ! $non_bank_cash_present) + $this->messages->add('No Stock Item selected.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + + /* Checking for Valid Ledgers A/C */ + foreach ($data_all_ledger_dc as $id => $ledger_data) + { + if ($data_all_ledger_id[$id] < 1) + continue; + + /* Check for valid ledger id */ + $this->db->from('ledgers')->where('id', $data_all_ledger_id[$id]); + $valid_ledger_q = $this->db->get(); + if ($valid_ledger_q->num_rows() < 1) { - $this->messages->add('Need to Debit or Credit atleast one NON - Bank or Cash A/C.', 'error'); + $this->messages->add('Invalid Ledger A/C.', 'error'); $this->template->load('template', 'inventory/stockvoucher/add', $data); return; } @@ -300,6 +306,7 @@ class StockVoucher extends Controller { $data_tag = NULL; $data_type = $voucher_type_id; $data_date = date_php_to_mysql($data_date); // Converting date to MySQL + $data_total_amount = 0; $voucher_id = NULL;
$this->db->trans_start(); @@ -321,6 +328,58 @@ class StockVoucher extends Controller { $voucher_id = $this->db->insert_id(); }
+ /* Adding main - account */ + $insert_data = array( + 'voucher_id' => $voucher_id, + 'ledger_id' => $data_main_account, + 'amount' => $data_total_amount, + 'dc' => '', + ); + if ($current_voucher_type['stock_voucher_type'] == '1') + $insert_data['dc'] = 'D'; + else + $insert_data['dc'] = 'C'; + if ( ! $this->db->insert('voucher_items', $insert_data)) + { + $this->db->trans_rollback(); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->messages->add('Error adding Purchase Ledger A/C - ' . $data_main_account . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting purchase ledger " . "[id:" . $data_main_account . "]"); + } else { + $this->messages->add('Error adding Sale Ledger A/C - ' . $data_main_account . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting sale ledger " . "[id:" . $data_main_account . "]"); + } + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + + /* Adding main - entity */ + $insert_data = array( + 'voucher_id' => $voucher_id, + 'ledger_id' => $data_entity_account, + 'amount' => $data_total_amount, + 'dc' => '', + ); + if ($current_voucher_type['stock_voucher_type'] == '1') + $insert_data['dc'] = 'C'; + else + $insert_data['dc'] = 'D'; + if ( ! $this->db->insert('voucher_items', $insert_data)) + { + $this->db->trans_rollback(); + if ($current_voucher_type['stock_voucher_type'] == '1') + { + $this->messages->add('Error adding Creditor (Supplier) - ' . $data_entity_account . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting creditor ledger " . "[id:" . $data_entity_account . "]"); + } else { + $this->messages->add('Error adding Debtor (Customer) - ' . $data_entity_account . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting debtor ledger " . "[id:" . $data_entity_account . "]"); + } + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + /* Adding ledger accounts */ $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); $data_all_ledger_id = $this->input->post('ledger_id', TRUE); @@ -1106,6 +1165,14 @@ class StockVoucher extends Controller { 'value' => '', 'class' => 'rate-item', ); + $stock_item_discount = array( + 'name' => 'stock_item_discount[' . $i . ']', + 'id' => 'stock_item_discount[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => '', + 'class' => 'discount-item', + ); $stock_item_amount = array( 'name' => 'stock_item_amount[' . $i . ']', 'id' => 'stock_item_amount[' . $i . ']', @@ -1119,6 +1186,7 @@ class StockVoucher extends Controller { echo "<td>" . form_input_stock_item('stock_item_id[' . $i . ']', 0) . "</td>"; echo "<td>" . form_input($stock_item_quantity) . "</td>"; echo "<td>" . form_input($stock_item_rate_per_unit) . "</td>"; + echo "<td>" . form_input($stock_item_discount) . "</td>"; echo "<td>" . form_input($stock_item_amount) . "</td>"; echo '<td>'; echo img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Stock Item', 'class' => 'addstockrow')); diff --git a/system/application/controllers/ledger.php b/system/application/controllers/ledger.php index bff86cf..13a5550 100644 --- a/system/application/controllers/ledger.php +++ b/system/application/controllers/ledger.php @@ -62,8 +62,8 @@ class Ledger extends Controller { $data['affects_inventory_options'] = array( '2' => 'Purchases Ledger A/C', '3' => 'Sales Ledger A/C', - '4' => 'Debtor (Customer)', - '5' => 'Creditor (Supplier)', + '4' => 'Creditor (Supplier)', + '5' => 'Debtor (Customer)', ); $data['affects_inventory_option_active'] = '2';
@@ -243,8 +243,8 @@ class Ledger extends Controller { $data['affects_inventory_options'] = array( '2' => 'Purchases Ledger A/C', '3' => 'Sales Ledger A/C', - '4' => 'Debtor (Customer)', - '5' => 'Creditor (Supplier)', + '4' => 'Creditor (Supplier)', + '5' => 'Debtor (Customer)', ); if ($ledger_data->type <= 0) { diff --git a/system/application/helpers/MY_form_helper.php b/system/application/helpers/MY_form_helper.php index cdc5825..7880e2b 100644 --- a/system/application/helpers/MY_form_helper.php +++ b/system/application/helpers/MY_form_helper.php @@ -70,6 +70,10 @@ if ( ! function_exists('form_input_ledger')) $options = $CI->Ledger_model->get_all_ledgers_purchase(); else if ($type == 'creditor') $options = $CI->Ledger_model->get_all_ledgers_creditor(); + else if ($type == 'sale') + $options = $CI->Ledger_model->get_all_ledgers_sale(); + else if ($type == 'debtor') + $options = $CI->Ledger_model->get_all_ledgers_debtor(); else $options = $CI->Ledger_model->get_all_ledgers();
diff --git a/system/application/models/ledger_model.php b/system/application/models/ledger_model.php index d50bcbe..e152bb0 100644 --- a/system/application/models/ledger_model.php +++ b/system/application/models/ledger_model.php @@ -7,6 +7,7 @@ class Ledger_model extends Model { parent::Model(); }
+ /**************************** GET LEDGERS METHODS *********************/ function get_all_ledgers() { $options = array(); @@ -76,7 +77,33 @@ class Ledger_model extends Model { { $options = array(); $options[0] = "(Please Select)"; - $this->db->from('ledgers')->where('type', 5)->order_by('name', 'asc'); + $this->db->from('ledgers')->where('type', 4)->or_where('type', 1)->order_by('name', 'asc'); + $ledger_q = $this->db->get(); + foreach ($ledger_q->result() as $row) + { + $options[$row->id] = $row->name; + } + return $options; + } + + function get_all_ledgers_sale() + { + $options = array(); + $options[0] = "(Please Select)"; + $this->db->from('ledgers')->where('type', 3)->order_by('name', 'asc'); + $ledger_q = $this->db->get(); + foreach ($ledger_q->result() as $row) + { + $options[$row->id] = $row->name; + } + return $options; + } + + function get_all_ledgers_debtor() + { + $options = array(); + $options[0] = "(Please Select)"; + $this->db->from('ledgers')->where('type', 5)->or_where('type', 1)->order_by('name', 'asc'); $ledger_q = $this->db->get(); foreach ($ledger_q->result() as $row) { diff --git a/system/application/views/inventory/stockvoucher/add.php b/system/application/views/inventory/stockvoucher/add.php index 83a68bc..31c19c1 100644 --- a/system/application/views/inventory/stockvoucher/add.php +++ b/system/application/views/inventory/stockvoucher/add.php @@ -13,13 +13,16 @@ $(document).ready(function() { $(this).parent().next().children().attr('value', ""); $(this).parent().next().next().children().attr('value', ""); $(this).parent().next().next().next().children().attr('value', ""); + $(this).parent().next().next().next().next().children().attr('value', ""); $(this).parent().next().children().attr('disabled', 'disabled'); $(this).parent().next().next().children().attr('disabled', 'disabled'); $(this).parent().next().next().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().next().next().children().attr('disabled', 'disabled'); } else { $(this).parent().next().children().attr('disabled', ''); $(this).parent().next().next().children().attr('disabled', ''); $(this).parent().next().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().next().children().attr('disabled', ''); $(this).parent().prev().children().trigger('change'); } var stockid = $(this).val(); @@ -32,15 +35,15 @@ $(document).ready(function() { if (isNaN(stock_bal)) stock_bal = 0; if (stock_bal == 0) - rowid.parent().next().next().next().next().next().children().text("0"); + rowid.parent().next().next().next().next().next().next().children().text("0"); else if (stock_bal < 0) - rowid.parent().next().next().next().next().next().next().children().text(data); + rowid.parent().next().next().next().next().next().next().next().children().text(data); else - rowid.parent().next().next().next().next().next().next().children().text(data); + rowid.parent().next().next().next().next().next().next().next().children().text(data); } }); } else { - rowid.parent().next().next().next().next().next().next().children().text(""); + rowid.parent().next().next().next().next().next().next().next().children().text(""); } });
@@ -49,18 +52,31 @@ $(document).ready(function() { calculateRowTotal(rowid.parent().prev()); });
+ $('table td .rate-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev().prev()); + }); + + $('table td .discount-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev().prev().prev()); + }); + var calculateRowTotal = function(itemrow) { var item_quantity = itemrow.next().children().val(); var item_rate_per_unit = itemrow.next().next().children().val(); - var item_amount = itemrow.next().next().next().children().val(); + var item_discount = itemrow.next().next().next().children().val();
item_quantity = parseFloat(item_quantity); item_rate_per_unit = parseFloat(item_rate_per_unit); - if ( (!isNaN(item_quantity)) && (!isNaN(item_rate_per_unit)) ) + item_discount = parseFloat(item_discount); + if (isNaN(item_discount)) + item_discount = 0; + if ((!isNaN(item_quantity)) && (!isNaN(item_rate_per_unit))) { - item_amount = item_quantity * item_rate_per_unit; - itemrow.next().next().next().children().val(item_amount); - itemrow.next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); + var item_amount = (item_quantity * item_rate_per_unit) - item_discount; + itemrow.next().next().next().next().children().val(item_amount); + itemrow.next().next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); } }
@@ -159,7 +175,7 @@ $(document).ready(function() { </script>
<?php - echo form_open('voucher/add/' . $current_voucher_type['label']); + echo form_open('inventory/stockvoucher/add/' . $current_voucher_type['label']); echo "<p>"; echo "<span id="tooltip-target-1">"; echo form_label('Voucher Number', 'voucher_number'); @@ -176,32 +192,57 @@ $(document).ready(function() { echo "<span id="tooltip-content-2">Date format is " . $this->config->item('account_date_format') . ".</span>"; echo "</p>";
- echo "<p>"; - echo "<table border=0 cellpadding=2>"; - echo "<tr>"; - echo "<td align="right">"; - echo form_label('Purchase Ledger A/C', 'purchase_ledger_id'); - echo "</td>"; - echo "<td>"; - echo form_input_ledger('purchase_ledger_id', '', '', $type = 'purchase'); - echo "</td>"; - echo "</tr>"; - - echo "<tr>"; - echo "<td align="right">"; - echo form_label('Creditor (Supplier)', 'creditor_ledger_id'); - echo "</td>"; - echo "<td>"; - echo form_input_ledger('creditor_ledger_id', '', '', $type = 'creditor'); - echo "</td>"; - echo "</tr>"; - echo "</table>"; - echo "</p>"; + if ($current_voucher_type['stock_voucher_type'] == '1') + { + echo "<p>"; + echo "<table border=0 cellpadding=2>"; + echo "<tr>"; + echo "<td align="right">"; + echo form_label('Purchase Ledger A/C', 'main_account'); + echo "</td>"; + echo "<td>"; + echo form_input_ledger('main_account', $main_account_active, '', $type = 'purchase'); + echo "</td>"; + echo "</tr>"; + + echo "<tr>"; + echo "<td align="right">"; + echo form_label('Creditor (Supplier)', 'main_entity'); + echo "</td>"; + echo "<td>"; + echo form_input_ledger('main_entity', $main_entity_active, '', $type = 'creditor'); + echo "</td>"; + echo "</tr>"; + echo "</table>"; + echo "</p>"; + } else { + echo "<p>"; + echo "<table border=0 cellpadding=2>"; + echo "<tr>"; + echo "<td align="right">"; + echo form_label('Sales Ledger A/C', 'main_account'); + echo "</td>"; + echo "<td>"; + echo form_input_ledger('main_account', $main_account_active, '', $type = 'sale'); + echo "</td>"; + echo "</tr>"; + + echo "<tr>"; + echo "<td align="right">"; + echo form_label('Debtor (Customer)', 'main_entity'); + echo "</td>"; + echo "<td>"; + echo form_input_ledger('main_entity', $main_entity_active, '', $type = 'debtor'); + echo "</td>"; + echo "</tr>"; + echo "</table>"; + echo "</p>"; + }
echo "<p></p>";
echo "<table class="voucher-table">"; - echo "<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate Per Unit</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + echo "<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate Per Unit</th><th>Discount</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>";
foreach ($stock_item_id as $i => $row) { @@ -221,6 +262,14 @@ $(document).ready(function() { 'value' => '', 'class' => 'rate-item', ); + $stock_item_discount = array( + 'name' => 'stock_item_discount[' . $i . ']', + 'id' => 'stock_item_discount[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => '', + 'class' => 'discount-item', + ); $stock_item_amount = array( 'name' => 'stock_item_amount[' . $i . ']', 'id' => 'stock_item_amount[' . $i . ']', @@ -234,6 +283,7 @@ $(document).ready(function() { echo "<td>" . form_input_stock_item('stock_item_id[' . $i . ']', 0) . "</td>"; echo "<td>" . form_input($stock_item_quantity) . "</td>"; echo "<td>" . form_input($stock_item_rate_per_unit) . "</td>"; + echo "<td>" . form_input($stock_item_discount) . "</td>"; echo "<td>" . form_input($stock_item_amount) . "</td>";
echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addstockrow')) . "</td>"; @@ -249,15 +299,15 @@ $(document).ready(function() { echo "<br />";
echo "<table class="voucher-table">"; - echo "<thead><tr><th>Type</th><th>Ledger A/C</th><th>Rate</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + echo "<thead><tr><th>Type</th><th>Ledger A/C</th><th>Rate %</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>";
foreach ($ledger_dc as $i => $ledger) { $rate_item = array( 'name' => 'rate_item[' . $i . ']', 'id' => 'rate_item[' . $i . ']', - 'maxlength' => '15', - 'size' => '15', + 'maxlength' => '5', + 'size' => '5', 'value' => isset($dr_amount[$i]) ? $dr_amount[$i] : "", 'class' => 'dr-item', );
commit 38a185b7893e5ce5c67955654a59a003ee86b773 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sat Feb 12 12:10:26 2011 +0530
Added development vesrion warning
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/libraries/Startup.php b/system/application/libraries/Startup.php index d658223..f0af27d 100644 --- a/system/application/libraries/Startup.php +++ b/system/application/libraries/Startup.php @@ -16,6 +16,8 @@ class Startup $CI->db->trans_strict(FALSE); $CI->load->library('general');
+ $CI->messages->add('This is a development version of webzash not meant for production use. You can get the stable version from ' . anchor('http://webzash.org/download', 'http://webzash.org/download'), 'error'); + /* Skip checking if accessing admin section*/ if ($CI->uri->segment(1) == "admin") return;
commit f134c5d03b42ba3f05c73b6325b66b6dd3501f74 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Fri Feb 11 16:44:43 2011 +0530
Added stock_voucher_type to voucher types
- stock_voucher_type can be Purchases or Sales
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/db-update.txt b/db-update.txt index 60f62b7..0561c99 100644 --- a/db-update.txt +++ b/db-update.txt @@ -5,6 +5,10 @@ UPDATE ledgers SET type = '0' WHERE type = 'N';
ALTER TABLE ledgers CHANGE type type INT(2) NOT NULL DEFAULT '0';
+ALTER TABLE voucher_types ADD stock_voucher_type INT(2) NOT NULL DEFAULT '1'; + +ALTER TABLE voucher_types CHANGE bank_cash_ledger_restriction bank_cash_ledger_restriction INT(2) NOT NULL DEFAULT '1'; + CREATE TABLE IF NOT EXISTS stock_units ( id int(11) NOT NULL AUTO_INCREMENT, symbol varchar(15) NOT NULL, diff --git a/system/application/controllers/admin/schema.sql b/system/application/controllers/admin/schema.sql index 299bd14..ca914a3 100644 --- a/system/application/controllers/admin/schema.sql +++ b/system/application/controllers/admin/schema.sql @@ -23,11 +23,12 @@ CREATE TABLE IF NOT EXISTS voucher_types ( name varchar(100) NOT NULL, description varchar(255) NOT NULL, base_type int(2) NOT NULL, + bank_cash_ledger_restriction int(2) NOT NULL DEFAULT '1', + stock_voucher_type int(2) NOT NULL DEFAULT '1', numbering int(2) NOT NULL, prefix varchar(10) NOT NULL, suffix varchar(10) NOT NULL, zero_padding int(2) NOT NULL, - bank_cash_ledger_restriction int(2) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
diff --git a/system/application/controllers/setting/vouchertypes.php b/system/application/controllers/setting/vouchertypes.php index a5d368e..9506bac 100644 --- a/system/application/controllers/setting/vouchertypes.php +++ b/system/application/controllers/setting/vouchertypes.php @@ -100,10 +100,15 @@ class VoucherTypes extends Controller { '4' => 'Only Bank or Cash A/C can be present on both Debit and Credit side', '5' => 'Only NON Bank or Cash A/C can be present on both Debit and Credit side', ); + $data['stock_voucher_types'] = array( + '1' => 'Purchases', + '2' => 'Sales', + );
$data['voucher_type_base_type_active'] = '1'; $data['voucher_type_numbering_active'] = '1'; $data['bank_cash_ledger_restriction_active'] = '1'; + $data['stock_voucher_type_active'] = '1';
/* Repopulating form */ if ($_POST) @@ -118,6 +123,7 @@ class VoucherTypes extends Controller { $data['voucher_type_base_type_active'] = $this->input->post('voucher_type_base_type', TRUE); $data['voucher_type_numbering_active'] = $this->input->post('voucher_type_numbering', TRUE); $data['bank_cash_ledger_restriction_active'] = $this->input->post('bank_cash_ledger_restriction', TRUE); + $data['stock_voucher_type_active'] = $this->input->post('stock_voucher_type', TRUE); }
/* Form validations */ @@ -146,6 +152,7 @@ class VoucherTypes extends Controller { $data_voucher_type_base_type = $this->input->post('voucher_type_base_type', TRUE); $data_voucher_type_numbering = $this->input->post('voucher_type_numbering', TRUE); $data_bank_cash_ledger_restriction = $this->input->post('bank_cash_ledger_restriction', TRUE); + $data_stock_voucher_type = $this->input->post('stock_voucher_type', TRUE);
if (($data_voucher_type_base_type < 1) or ($data_voucher_type_base_type > 2)) $data_voucher_type_base_type = 1; @@ -156,6 +163,9 @@ class VoucherTypes extends Controller { if (($data_bank_cash_ledger_restriction < 1) or ($data_bank_cash_ledger_restriction > 5)) $data_bank_cash_ledger_restriction = 1;
+ if (($data_stock_voucher_type < 1) or ($data_stock_voucher_type > 2)) + $data_stock_voucher_type = 1; + /* Calculating Voucher Type Id */ $last_id = 1; $this->db->select_max('id', 'lastid')->from('voucher_types'); @@ -178,6 +188,7 @@ class VoucherTypes extends Controller { 'suffix' => $data_voucher_type_suffix, 'zero_padding' => $data_voucher_type_zero_padding, 'bank_cash_ledger_restriction' => $data_bank_cash_ledger_restriction, + 'stock_voucher_type' => $data_stock_voucher_type, ); if ( ! $this->db->insert('voucher_types', $insert_data)) { @@ -288,10 +299,15 @@ class VoucherTypes extends Controller { '4' => 'Only Bank or Cash A/C can be present on both Debit and Credit side', '5' => 'Only NON Bank or Cash A/C can be present on both Debit and Credit side', ); + $data['stock_voucher_types'] = array( + '1' => 'Purchases', + '2' => 'Sales', + );
$data['voucher_type_base_type_active'] = $voucher_type_data->base_type; $data['voucher_type_numbering_active'] = $voucher_type_data->numbering; $data['bank_cash_ledger_restriction_active'] = $voucher_type_data->bank_cash_ledger_restriction; + $data['stock_voucher_type_active'] = $voucher_type_data->stock_voucher_type; $data['voucher_type_id'] = $id;
/* Repopulating form */ @@ -307,6 +323,7 @@ class VoucherTypes extends Controller { $data['voucher_type_base_type_active'] = $this->input->post('voucher_type_base_type', TRUE); $data['voucher_type_numbering_active'] = $this->input->post('voucher_type_numbering', TRUE); $data['bank_cash_ledger_restriction_active'] = $this->input->post('bank_cash_ledger_restriction', TRUE); + $data['stock_voucher_type_active'] = $this->input->post('stock_voucher_type', TRUE); }
/* Form validations */ @@ -336,6 +353,7 @@ class VoucherTypes extends Controller { $data_voucher_type_base_type = $this->input->post('voucher_type_base_type', TRUE); $data_voucher_type_numbering = $this->input->post('voucher_type_numbering', TRUE); $data_bank_cash_ledger_restriction = $this->input->post('bank_cash_ledger_restriction', TRUE); + $data_stock_voucher_type = $this->input->post('stock_voucher_type', TRUE);
if (($data_voucher_type_base_type < 1) or ($data_voucher_type_base_type > 2)) $data_voucher_type_base_type = 1; @@ -346,6 +364,9 @@ class VoucherTypes extends Controller { if (($data_bank_cash_ledger_restriction < 1) or ($data_bank_cash_ledger_restriction > 5)) $data_bank_cash_ledger_restriction = 1;
+ if (($data_stock_voucher_type < 1) or ($data_stock_voucher_type > 2)) + $data_stock_voucher_type = 1; + $this->db->trans_start(); $update_data = array( 'label' => $data_voucher_type_label, @@ -357,6 +378,7 @@ class VoucherTypes extends Controller { 'suffix' => $data_voucher_type_suffix, 'zero_padding' => $data_voucher_type_zero_padding, 'bank_cash_ledger_restriction' => $data_bank_cash_ledger_restriction, + 'stock_voucher_type' => $data_stock_voucher_type, ); if ( ! $this->db->where('id', $data_voucher_type_id)->update('voucher_types', $update_data)) { diff --git a/system/application/helpers/custom_helper.php b/system/application/helpers/custom_helper.php index 15b3029..f1071cb 100644 --- a/system/application/helpers/custom_helper.php +++ b/system/application/helpers/custom_helper.php @@ -117,11 +117,12 @@ if ( ! function_exists('voucher_type_info')) 'label' => $voucher_type_all[$voucher_type_id]['label'], 'name' => $voucher_type_all[$voucher_type_id]['name'], 'base_type' => $voucher_type_all[$voucher_type_id]['base_type'], + 'bank_cash_ledger_restriction' => $voucher_type_all[$voucher_type_id]['bank_cash_ledger_restriction'], + 'stock_voucher_type' => $voucher_type_all[$voucher_type_id]['stock_voucher_type'], 'numbering' => $voucher_type_all[$voucher_type_id]['numbering'], 'prefix' => $voucher_type_all[$voucher_type_id]['prefix'], 'suffix' => $voucher_type_all[$voucher_type_id]['suffix'], 'zero_padding' => $voucher_type_all[$voucher_type_id]['zero_padding'], - 'bank_cash_ledger_restriction' => $voucher_type_all[$voucher_type_id]['bank_cash_ledger_restriction'], ); } else { return array( @@ -129,11 +130,12 @@ if ( ! function_exists('voucher_type_info')) 'label' => '', 'name' => '(Unkonwn)', 'base_type' => 1, + 'bank_cash_ledger_restriction' => 1, + 'stock_voucher_type' => 1, 'numbering' => 1, 'prefix' => '', 'suffix' => '', 'zero_padding' => 0, - 'bank_cash_ledger_restriction' => 5, ); } } diff --git a/system/application/libraries/General.php b/system/application/libraries/General.php index 9f0d101..eab6e19 100644 --- a/system/application/libraries/General.php +++ b/system/application/libraries/General.php @@ -189,11 +189,12 @@ class General { 'name' => $row->name, 'description' => $row->description, 'base_type' => $row->base_type, + 'bank_cash_ledger_restriction' => $row->bank_cash_ledger_restriction, + 'stock_voucher_type' => $row->stock_voucher_type, 'numbering' => $row->numbering, 'prefix' => $row->prefix, 'suffix' => $row->suffix, 'zero_padding' => $row->zero_padding, - 'bank_cash_ledger_restriction' => $row->bank_cash_ledger_restriction, ); } $CI->config->set_item('account_voucher_types', $voucher_type_config); diff --git a/system/application/views/setting/vouchertypes/add.php b/system/application/views/setting/vouchertypes/add.php index a312630..d3f81aa 100644 --- a/system/application/views/setting/vouchertypes/add.php +++ b/system/application/views/setting/vouchertypes/add.php @@ -28,6 +28,18 @@ echo "</p>";
echo "<p>"; + echo form_label('Restrictions', 'bank_cash_ledger_restriction'); + echo "<br />"; + echo form_dropdown('bank_cash_ledger_restriction', $bank_cash_ledger_restrictions, $bank_cash_ledger_restriction_active); + echo "</p>"; + + echo "<p>"; + echo form_label('Stock Voucher Type', 'stock_voucher_type'); + echo "<br />"; + echo form_dropdown('stock_voucher_type', $stock_voucher_types, $stock_voucher_type_active); + echo "</p>"; + + echo "<p>"; echo form_label('Voucher Numbering', 'voucher_type_numbering'); echo "<br />"; echo form_dropdown('voucher_type_numbering', $voucher_type_numberings, $voucher_type_numbering_active); @@ -52,12 +64,6 @@ echo "</p>";
echo "<p>"; - echo form_label('Restrictions', 'bank_cash_ledger_restriction'); - echo "<br />"; - echo form_dropdown('bank_cash_ledger_restriction', $bank_cash_ledger_restrictions, $bank_cash_ledger_restriction_active); - echo "</p>"; - - echo "<p>"; echo form_submit('submit', 'Create'); echo " "; echo anchor('setting/vouchertypes', 'Back', 'Back to Voucher Types'); diff --git a/system/application/views/setting/vouchertypes/edit.php b/system/application/views/setting/vouchertypes/edit.php index b3a8513..fa16410 100644 --- a/system/application/views/setting/vouchertypes/edit.php +++ b/system/application/views/setting/vouchertypes/edit.php @@ -28,6 +28,18 @@ echo "</p>";
echo "<p>"; + echo form_label('Restrictions', 'bank_cash_ledger_restriction'); + echo "<br />"; + echo form_dropdown('bank_cash_ledger_restriction', $bank_cash_ledger_restrictions, $bank_cash_ledger_restriction_active); + echo "</p>"; + + echo "<p>"; + echo form_label('Stock Voucher Type', 'stock_voucher_type'); + echo "<br />"; + echo form_dropdown('stock_voucher_type', $stock_voucher_types, $stock_voucher_type_active); + echo "</p>"; + + echo "<p>"; echo form_label('Voucher Numbering', 'voucher_type_numbering'); echo "<br />"; echo form_dropdown('voucher_type_numbering', $voucher_type_numberings, $voucher_type_numbering_active); @@ -52,12 +64,6 @@ echo "</p>";
echo "<p>"; - echo form_label('Restrictions', 'bank_cash_ledger_restriction'); - echo "<br />"; - echo form_dropdown('bank_cash_ledger_restriction', $bank_cash_ledger_restrictions, $bank_cash_ledger_restriction_active); - echo "</p>"; - - echo "<p>"; echo form_submit('submit', 'Update'); echo " "; echo anchor('setting/vouchertypes', 'Back', 'Back to Voucher Types');
commit a0e5ef873fde1038a0a40eb1185240cf1fbad420 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Wed Feb 9 17:35:08 2011 +0530
Added basic purchase voucher structure
- Updated database schema to add table for stock voucher items - Added stub stock item balance method - Added purcahse voucher add structure - Added permissions to view/add/edit/delete stock vouchers
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/assets/css/tables.css b/system/application/assets/css/tables.css index 6ebba75..567daa9 100644 --- a/system/application/assets/css/tables.css +++ b/system/application/assets/css/tables.css @@ -71,6 +71,33 @@ tr.total-area { }
/******************************************************************************/ +/************************* STOCK VOUCHER TABLE ********************************/ +/******************************************************************************/ + +.stock-voucher-table { + font-family:"Lucida Sans Unicode", "Lucida Grande", Sans-Serif; + font-size:14px; + border-collapse:collapse; + text-align:left; +} + +.stock-voucher-table th { + font-weight:normal; + color:#000000; + padding:5px 8px; + background-color:#EEEEEE; +} + +.stock-voucher-table td { + color:#000000; + padding:8px 8px 8px 8px; +} + +.stock-voucher-table tr.new-row { + background-color:#FFFFE0; +} + +/******************************************************************************/ /****************************** CUSTOM TABLES *********************************/ /******************************************************************************/
diff --git a/system/application/controllers/admin/schema.sql b/system/application/controllers/admin/schema.sql index 6e4d706..299bd14 100644 --- a/system/application/controllers/admin/schema.sql +++ b/system/application/controllers/admin/schema.sql @@ -124,8 +124,17 @@ CREATE TABLE IF NOT EXISTS stock_items ( name varchar(100) NOT NULL, costing_method int(2) NOT NULL, op_balance_quantity float NOT NULL, - op_balance_rate_per_unit decimal(15,2) NOT NULL, - op_balance_total_value decimal(15,2) NOT NULL, + op_balance_rate_per_unit decimal(15,2) NOT NULL DEFAULT '0.00', + op_balance_total_value decimal(15,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
+CREATE TABLE IF NOT EXISTS stock_voucher_items ( + id int(11) NOT NULL AUTO_INCREMENT, + stock_item_id int(11) NOT NULL, + quantity float NOT NULL, + rate_per_unit decimal(15,2) NOT NULL DEFAULT '0.00', + discount varchar(15) NOT NULL, + total decimal(15,2) NOT NULL DEFAULT '0.00', + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; diff --git a/system/application/controllers/inventory/stockitem.php b/system/application/controllers/inventory/stockitem.php index e8fcdd0..5193c51 100644 --- a/system/application/controllers/inventory/stockitem.php +++ b/system/application/controllers/inventory/stockitem.php @@ -386,6 +386,15 @@ class StockItem extends Controller { } return; } + + function balance($stock_ledger_id = 0) + { + if ($stock_ledger_id > 0) + echo $this->Stock_Item_model->get_stock_item_balance($stock_ledger_id); + else + echo ""; + return; + } }
/* End of file stockitem.php */ diff --git a/system/application/controllers/inventory/stockvoucher.php b/system/application/controllers/inventory/stockvoucher.php new file mode 100644 index 0000000..b97aaea --- /dev/null +++ b/system/application/controllers/inventory/stockvoucher.php @@ -0,0 +1,1137 @@ +<?php + +class StockVoucher extends Controller { + + function StockVoucher() + { + parent::Controller(); + $this->load->model('Voucher_model'); + $this->load->model('Ledger_model'); + $this->load->model('Tag_model'); + return; + } + + function index() + { + redirect('voucher/show/all'); + return; + } + + function view($voucher_type, $voucher_id = 0) + { + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + $this->template->set('page_title', 'View ' . $current_voucher_type['name'] . ' Voucher'); + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + /* Load current voucher details */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->order_by('id', 'asc'); + $cur_voucher_ledgers = $this->db->get(); + if ($cur_voucher_ledgers->num_rows() < 1) + { + $this->messages->add('Voucher has no associated Ledger A/C's.', 'error'); + } + $data['cur_voucher'] = $cur_voucher; + $data['cur_voucher_ledgers'] = $cur_voucher_ledgers; + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + $this->template->load('template', 'voucher/view', $data); + return; + } + + function add($voucher_type) + { + /* Check access */ + if ( ! check_access('create stock voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('voucher/show/' . $voucher_type); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + $this->template->set('page_title', 'New ' . $current_voucher_type['name'] . ' Voucher'); + + /* Form fields */ + $data['voucher_number'] = array( + 'name' => 'voucher_number', + 'id' => 'voucher_number', + 'maxlength' => '11', + 'size' => '11', + 'value' => '', + ); + $data['voucher_date'] = array( + 'name' => 'voucher_date', + 'id' => 'voucher_date', + 'maxlength' => '11', + 'size' => '11', + 'value' => date_today_php(), + ); + $data['voucher_narration'] = array( + 'name' => 'voucher_narration', + 'id' => 'voucher_narration', + 'cols' => '50', + 'rows' => '4', + 'value' => '', + ); + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + $data['voucher_tags'] = $this->Tag_model->get_all_tags(); + $data['voucher_tag'] = 0; + + /* Form validations */ + if ($current_voucher_type['numbering'] == '2') + $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|required|is_natural_no_zero|uniquevoucherno[' . $voucher_type_id . ']'); + else if ($current_voucher_type['numbering'] == '3') + $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|is_natural_no_zero|uniquevoucherno[' . $voucher_type_id . ']'); + else + $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|is_natural_no_zero|uniquevoucherno[' . $voucher_type_id . ']'); + $this->form_validation->set_rules('voucher_date', 'Voucher Date', 'trim|required|is_date|is_date_within_range'); + $this->form_validation->set_rules('voucher_narration', 'trim'); + $this->form_validation->set_rules('voucher_tag', 'Tag', 'trim|is_natural'); + + /* Debit and Credit amount validation */ + if ($_POST) + { + foreach ($this->input->post('ledger_dc', TRUE) as $id => $ledger_data) + { + $this->form_validation->set_rules('dr_amount[' . $id . ']', 'Debit Amount', 'trim|currency'); + $this->form_validation->set_rules('cr_amount[' . $id . ']', 'Credit Amount', 'trim|currency'); + } + } + + /* Repopulating form */ + if ($_POST) + { + $data['voucher_number']['value'] = $this->input->post('voucher_number', TRUE); + $data['voucher_date']['value'] = $this->input->post('voucher_date', TRUE); + $data['voucher_narration']['value'] = $this->input->post('voucher_narration', TRUE); + $data['voucher_tag'] = $this->input->post('voucher_tag', TRUE); + + $data['ledger_dc'] = $this->input->post('ledger_dc', TRUE); + $data['ledger_id'] = $this->input->post('ledger_id', TRUE); + $data['dr_amount'] = $this->input->post('dr_amount', TRUE); + $data['cr_amount'] = $this->input->post('cr_amount', TRUE); + } else { + for ($count = 0; $count <= 1; $count++) + { + $data['ledger_dc'][$count] = "D"; + $data['ledger_id'][$count] = 0; + $data['rate'][$count] = ""; + $data['amount'][$count] = ""; + } + for ($count = 0; $count <= 3; $count++) + { + $data['stock_item_id'][$count] = '0'; + $data['stock_item_quantity'][$count] = ''; + $data['stock_item_rate_per_unit'][$count] = ''; + $data['stock_item_amount'][$count] = ''; + } + } + + if ($this->form_validation->run() == FALSE) + { + $this->messages->add(validation_errors(), 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + else + { + /* Checking for Valid Ledgers A/C and Debit and Credit Total */ + $data_all_ledger_id = $this->input->post('ledger_id', TRUE); + $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); + $data_all_dr_amount = $this->input->post('dr_amount', TRUE); + $data_all_cr_amount = $this->input->post('cr_amount', TRUE); + $dr_total = 0; + $cr_total = 0; + $bank_cash_present = FALSE; /* Whether atleast one Ledger A/C is Bank or Cash A/C */ + $non_bank_cash_present = FALSE; /* Whether atleast one Ledger A/C is NOT a Bank or Cash A/C */ + foreach ($data_all_ledger_dc as $id => $ledger_data) + { + if ($data_all_ledger_id[$id] < 1) + continue; + + /* Check for valid ledger id */ + $this->db->from('ledgers')->where('id', $data_all_ledger_id[$id]); + $valid_ledger_q = $this->db->get(); + if ($valid_ledger_q->num_rows() < 1) + { + $this->messages->add('Invalid Ledger A/C.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } else { + /* Check for valid ledger type */ + $valid_ledger = $valid_ledger_q->row(); + if ($current_voucher_type['bank_cash_ledger_restriction'] == '2') + { + if ($data_all_ledger_dc[$id] == 'D' && $valid_ledger->type == 1) + { + $bank_cash_present = TRUE; + } + if ($valid_ledger->type != 1) + $non_bank_cash_present = TRUE; + } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') + { + if ($data_all_ledger_dc[$id] == 'C' && $valid_ledger->type == 1) + { + $bank_cash_present = TRUE; + } + if ($valid_ledger->type != 1) + $non_bank_cash_present = TRUE; + } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '4') + { + if ($valid_ledger->type != 1) + { + $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers can have only Bank and Cash Ledgers A/C's.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '5') + { + if ($valid_ledger->type == 1) + { + $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers cannot have Bank and Cash Ledgers A/C's.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + } + } + + if ($data_all_ledger_dc[$id] == "D") + { + $dr_total += $data_all_dr_amount[$id]; + } else { + $cr_total += $data_all_cr_amount[$id]; + } + } + if ($dr_total != $cr_total) + { + $this->messages->add('Debit and Credit Total does not match!', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } else if ($dr_total == 0 && $cr_total == 0) { + $this->messages->add('Cannot save empty Voucher.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + /* Check if atleast one Bank or Cash Ledger A/C is present */ + if ($current_voucher_type['bank_cash_ledger_restriction'] == '2') + { + if ( ! $bank_cash_present) + { + $this->messages->add('Need to Debit atleast one Bank or Cash A/C.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + if ( ! $non_bank_cash_present) + { + $this->messages->add('Need to Debit or Credit atleast one NON - Bank or Cash A/C.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') + { + if ( ! $bank_cash_present) + { + $this->messages->add('Need to Credit atleast one Bank or Cash A/C.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + if ( ! $non_bank_cash_present) + { + $this->messages->add('Need to Debit or Credit atleast one NON - Bank or Cash A/C.', 'error'); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + } + + /* Adding main voucher */ + if ($current_voucher_type['numbering'] == '2') + { + $data_number = $this->input->post('voucher_number', TRUE); + } else if ($current_voucher_type['numbering'] == '3') { + $data_number = $this->input->post('voucher_number', TRUE); + if ( ! $data_number) + $data_number = NULL; + } else { + if ($this->input->post('voucher_number', TRUE)) + $data_number = $this->input->post('voucher_number', TRUE); + else + $data_number = $this->Voucher_model->next_voucher_number($voucher_type_id); + } + + $data_date = $this->input->post('voucher_date', TRUE); + $data_narration = $this->input->post('voucher_narration', TRUE); + $data_tag = $this->input->post('voucher_tag', TRUE); + if ($data_tag < 1) + $data_tag = NULL; + $data_type = $voucher_type_id; + $data_date = date_php_to_mysql($data_date); // Converting date to MySQL + $voucher_id = NULL; + + $this->db->trans_start(); + $insert_data = array( + 'number' => $data_number, + 'date' => $data_date, + 'narration' => $data_narration, + 'voucher_type' => $data_type, + 'tag_id' => $data_tag, + ); + if ( ! $this->db->insert('vouchers', $insert_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error addding Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting voucher"); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } else { + $voucher_id = $this->db->insert_id(); + } + + /* Adding ledger accounts */ + $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); + $data_all_ledger_id = $this->input->post('ledger_id', TRUE); + $data_all_dr_amount = $this->input->post('dr_amount', TRUE); + $data_all_cr_amount = $this->input->post('cr_amount', TRUE); + + $dr_total = 0; + $cr_total = 0; + foreach ($data_all_ledger_dc as $id => $ledger_data) + { + $data_ledger_dc = $data_all_ledger_dc[$id]; + $data_ledger_id = $data_all_ledger_id[$id]; + if ($data_ledger_id < 1) + continue; + $data_amount = 0; + if ($data_all_ledger_dc[$id] == "D") + { + $data_amount = $data_all_dr_amount[$id]; + $dr_total += $data_all_dr_amount[$id]; + } else { + $data_amount = $data_all_cr_amount[$id]; + $cr_total += $data_all_cr_amount[$id]; + } + $insert_ledger_data = array( + 'voucher_id' => $voucher_id, + 'ledger_id' => $data_ledger_id, + 'amount' => $data_amount, + 'dc' => $data_ledger_dc, + ); + if ( ! $this->db->insert('voucher_items', $insert_ledger_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error adding Ledger A/C - ' . $data_ledger_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed inserting voucher ledger item " . "[id:" . $data_ledger_id . "]"); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + } + + /* Updating Debit and Credit Total in vouchers table */ + $update_data = array( + 'dr_total' => $dr_total, + 'cr_total' => $cr_total, + ); + if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error updating Voucher total.', 'error'); + $this->logger->write_message("error", "Error adding " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " since failed updating debit and credit total"); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + + /* Success */ + $this->db->trans_complete(); + + $this->session->set_userdata('voucher_added_show_action', TRUE); + $this->session->set_userdata('voucher_added_id', $voucher_id); + $this->session->set_userdata('voucher_added_type_id', $voucher_type_id); + $this->session->set_userdata('voucher_added_type_label', $current_voucher_type['label']); + $this->session->set_userdata('voucher_added_type_name', $current_voucher_type['name']); + $this->session->set_userdata('voucher_added_number', $data_number); + + /* Showing success message in show() method since message is too long for storing it in session */ + $this->logger->write_message("success", "Added " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + redirect('voucher/show/' . $current_voucher_type['label']); + $this->template->load('template', 'inventory/stockvoucher/add', $data); + return; + } + return; + } + + function edit($voucher_type, $voucher_id = 0) + { + /* Check access */ + if ( ! check_access('edit voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('voucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + $this->template->set('page_title', 'Edit ' . $current_voucher_type['name'] . ' Voucher'); + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + /* Form fields - Voucher */ + $data['voucher_number'] = array( + 'name' => 'voucher_number', + 'id' => 'voucher_number', + 'maxlength' => '11', + 'size' => '11', + 'value' => $cur_voucher->number, + ); + $data['voucher_date'] = array( + 'name' => 'voucher_date', + 'id' => 'voucher_date', + 'maxlength' => '11', + 'size' => '11', + 'value' => date_mysql_to_php($cur_voucher->date), + ); + $data['voucher_narration'] = array( + 'name' => 'voucher_narration', + 'id' => 'voucher_narration', + 'cols' => '50', + 'rows' => '4', + 'value' => $cur_voucher->narration, + ); + $data['voucher_id'] = $voucher_id; + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + $data['voucher_tag'] = $cur_voucher->tag_id; + $data['voucher_tags'] = $this->Tag_model->get_all_tags(); + $data['has_reconciliation'] = FALSE; + + /* Load current ledger details if not $_POST */ + if ( ! $_POST) + { + $this->db->from('voucher_items')->where('voucher_id', $voucher_id); + $cur_ledgers_q = $this->db->get(); + if ($cur_ledgers_q->num_rows <= 0) + { + $this->messages->add('No Ledger A/C's found!', 'error'); + } + $counter = 0; + foreach ($cur_ledgers_q->result() as $row) + { + $data['ledger_dc'][$counter] = $row->dc; + $data['ledger_id'][$counter] = $row->ledger_id; + if ($row->dc == "D") + { + $data['dr_amount'][$counter] = $row->amount; + $data['cr_amount'][$counter] = ""; + } else { + $data['dr_amount'][$counter] = ""; + $data['cr_amount'][$counter] = $row->amount; + } + if ($row->reconciliation_date) + $data['has_reconciliation'] = TRUE; + $counter++; + } + /* Two extra rows */ + $data['ledger_dc'][$counter] = 'D'; + $data['ledger_id'][$counter] = 0; + $data['dr_amount'][$counter] = ""; + $data['cr_amount'][$counter] = ""; + $counter++; + $data['ledger_dc'][$counter] = 'D'; + $data['ledger_id'][$counter] = 0; + $data['dr_amount'][$counter] = ""; + $data['cr_amount'][$counter] = ""; + $counter++; + } + + /* Form validations */ + if ($current_voucher_type['numbering'] == '3') + $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|is_natural_no_zero|uniquevouchernowithid[' . $voucher_type_id . '.' . $voucher_id . ']'); + else + $this->form_validation->set_rules('voucher_number', 'Voucher Number', 'trim|required|is_natural_no_zero|uniquevouchernowithid[' . $voucher_type_id . '.' . $voucher_id . ']'); + $this->form_validation->set_rules('voucher_date', 'Voucher Date', 'trim|required|is_date|is_date_within_range'); + $this->form_validation->set_rules('voucher_narration', 'trim'); + $this->form_validation->set_rules('voucher_tag', 'Tag', 'trim|is_natural'); + + /* Debit and Credit amount validation */ + if ($_POST) + { + foreach ($this->input->post('ledger_dc', TRUE) as $id => $ledger_data) + { + $this->form_validation->set_rules('dr_amount[' . $id . ']', 'Debit Amount', 'trim|currency'); + $this->form_validation->set_rules('cr_amount[' . $id . ']', 'Credit Amount', 'trim|currency'); + } + } + + /* Repopulating form */ + if ($_POST) + { + $data['voucher_number']['value'] = $this->input->post('voucher_number', TRUE); + $data['voucher_date']['value'] = $this->input->post('voucher_date', TRUE); + $data['voucher_narration']['value'] = $this->input->post('voucher_narration', TRUE); + $data['voucher_tag'] = $this->input->post('voucher_tag', TRUE); + $data['has_reconciliation'] = $this->input->post('has_reconciliation', TRUE); + + $data['ledger_dc'] = $this->input->post('ledger_dc', TRUE); + $data['ledger_id'] = $this->input->post('ledger_id', TRUE); + $data['dr_amount'] = $this->input->post('dr_amount', TRUE); + $data['cr_amount'] = $this->input->post('cr_amount', TRUE); + } + + if ($this->form_validation->run() == FALSE) + { + $this->messages->add(validation_errors(), 'error'); + $this->template->load('template', 'voucher/edit', $data); + } else { + /* Checking for Valid Ledgers A/C and Debit and Credit Total */ + $data_all_ledger_id = $this->input->post('ledger_id', TRUE); + $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); + $data_all_dr_amount = $this->input->post('dr_amount', TRUE); + $data_all_cr_amount = $this->input->post('cr_amount', TRUE); + $dr_total = 0; + $cr_total = 0; + $bank_cash_present = FALSE; /* Whether atleast one Ledger A/C is Bank or Cash A/C */ + $non_bank_cash_present = FALSE; /* Whether atleast one Ledger A/C is NOT a Bank or Cash A/C */ + foreach ($data_all_ledger_dc as $id => $ledger_data) + { + if ($data_all_ledger_id[$id] < 1) + continue; + + /* Check for valid ledger id */ + $this->db->from('ledgers')->where('id', $data_all_ledger_id[$id]); + $valid_ledger_q = $this->db->get(); + if ($valid_ledger_q->num_rows() < 1) + { + $this->messages->add('Invalid Ledger A/C.', 'error'); + $this->template->load('template', 'voucher/edit', $data); + return; + } else { + /* Check for valid ledger type */ + $valid_ledger = $valid_ledger_q->row(); + if ($current_voucher_type['bank_cash_ledger_restriction'] == '2') + { + if ($data_all_ledger_dc[$id] == 'D' && $valid_ledger->type == 1) + { + $bank_cash_present = TRUE; + } + if ($valid_ledger->type != 1) + $non_bank_cash_present = TRUE; + } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') + { + if ($data_all_ledger_dc[$id] == 'C' && $valid_ledger->type == 1) + { + $bank_cash_present = TRUE; + } + if ($valid_ledger->type != 1) + $non_bank_cash_present = TRUE; + } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '4') + { + if ($valid_ledger->type != 1) + { + $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers can have only Bank and Cash Ledgers A/C's.', 'error'); + $this->template->load('template', 'voucher/edit', $data); + return; + } + } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '5') + { + if ($valid_ledger->type == 1) + { + $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers cannot have Bank and Cash Ledgers A/C's.', 'error'); + $this->template->load('template', 'voucher/edit', $data); + return; + } + } + } + if ($data_all_ledger_dc[$id] == "D") + { + $dr_total += $data_all_dr_amount[$id]; + } else { + $cr_total += $data_all_cr_amount[$id]; + } + } + if ($dr_total != $cr_total) + { + $this->messages->add('Debit and Credit Total does not match!', 'error'); + $this->template->load('template', 'voucher/edit', $data); + return; + } else if ($dr_total == 0 && $cr_total == 0) { + $this->messages->add('Cannot save empty Voucher.', 'error'); + $this->template->load('template', 'voucher/edit', $data); + return; + } + /* Check if atleast one Bank or Cash Ledger A/C is present */ + if ($current_voucher_type['bank_cash_ledger_restriction'] == '2') + { + if ( ! $bank_cash_present) + { + $this->messages->add('Need to Debit atleast one Bank or Cash A/C.', 'error'); + $this->template->load('template', 'voucher/edit', $data); + return; + } + if ( ! $non_bank_cash_present) + { + $this->messages->add('Need to Debit or Credit atleast one NON - Bank or Cash A/C.', 'error'); + $this->template->load('template', 'voucher/edit', $data); + return; + } + } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') + { + if ( ! $bank_cash_present) + { + $this->messages->add('Need to Credit atleast one Bank or Cash A/C.', 'error'); + $this->template->load('template', 'voucher/edit', $data); + return; + } + if ( ! $non_bank_cash_present) + { + $this->messages->add('Need to Debit or Credit atleast one NON - Bank or Cash A/C.', 'error'); + $this->template->load('template', 'voucher/edit', $data); + return; + } + } + + /* Updating main voucher */ + if ($current_voucher_type['numbering'] == '3') { + $data_number = $this->input->post('voucher_number', TRUE); + if ( ! $data_number) + $data_number = NULL; + } else { + $data_number = $this->input->post('voucher_number', TRUE); + } + + $data_date = $this->input->post('voucher_date', TRUE); + $data_narration = $this->input->post('voucher_narration', TRUE); + $data_tag = $this->input->post('voucher_tag', TRUE); + if ($data_tag < 1) + $data_tag = NULL; + $data_type = $voucher_type_id; + $data_date = date_php_to_mysql($data_date); // Converting date to MySQL + $data_has_reconciliation = $this->input->post('has_reconciliation', TRUE); + + $this->db->trans_start(); + $update_data = array( + 'number' => $data_number, + 'date' => $data_date, + 'narration' => $data_narration, + 'tag_id' => $data_tag, + ); + if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error updating Voucher A/C.', 'error'); + $this->logger->write_message("error", "Error updating voucher details for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + $this->template->load('template', 'voucher/edit', $data); + return; + } + + /* TODO : Deleting all old ledger data, Bad solution */ + if ( ! $this->db->delete('voucher_items', array('voucher_id' => $voucher_id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting previous Ledger A/C's from Voucher.', 'error'); + $this->logger->write_message("error", "Error deleting previous voucher items for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + $this->template->load('template', 'voucher/edit', $data); + return; + } + + /* Adding ledger accounts */ + $data_all_ledger_dc = $this->input->post('ledger_dc', TRUE); + $data_all_ledger_id = $this->input->post('ledger_id', TRUE); + $data_all_dr_amount = $this->input->post('dr_amount', TRUE); + $data_all_cr_amount = $this->input->post('cr_amount', TRUE); + + $dr_total = 0; + $cr_total = 0; + foreach ($data_all_ledger_dc as $id => $ledger_data) + { + $data_ledger_dc = $data_all_ledger_dc[$id]; + $data_ledger_id = $data_all_ledger_id[$id]; + if ($data_ledger_id < 1) + continue; + $data_amount = 0; + if ($data_all_ledger_dc[$id] == "D") + { + $data_amount = $data_all_dr_amount[$id]; + $dr_total += $data_all_dr_amount[$id]; + } else { + $data_amount = $data_all_cr_amount[$id]; + $cr_total += $data_all_cr_amount[$id]; + } + + $insert_ledger_data = array( + 'voucher_id' => $voucher_id, + 'ledger_id' => $data_ledger_id, + 'amount' => $data_amount, + 'dc' => $data_ledger_dc, + ); + if ( ! $this->db->insert('voucher_items', $insert_ledger_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error adding Ledger A/C - ' . $data_ledger_id . ' to Voucher.', 'error'); + $this->logger->write_message("error", "Error adding Ledger A/C item [id:" . $data_ledger_id . "] for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + $this->template->load('template', 'voucher/edit', $data); + return; + } + } + + /* Updating Debit and Credit Total in vouchers table */ + $update_data = array( + 'dr_total' => $dr_total, + 'cr_total' => $cr_total, + ); + if ( ! $this->db->where('id', $voucher_id)->update('vouchers', $update_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error updating Voucher total.', 'error'); + $this->logger->write_message("error", "Error updating voucher total for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + $this->template->load('template', 'voucher/edit', $data); + return; + } + + /* Success */ + $this->db->trans_complete(); + + $this->session->set_userdata('voucher_updated_show_action', TRUE); + $this->session->set_userdata('voucher_updated_id', $voucher_id); + $this->session->set_userdata('voucher_updated_type_id', $voucher_type_id); + $this->session->set_userdata('voucher_updated_type_label', $current_voucher_type['label']); + $this->session->set_userdata('voucher_updated_type_name', $current_voucher_type['name']); + $this->session->set_userdata('voucher_updated_number', $data_number); + if ($data_has_reconciliation) + $this->session->set_userdata('voucher_updated_has_reconciliation', TRUE); + else + $this->session->set_userdata('voucher_updated_has_reconciliation', FALSE); + + /* Showing success message in show() method since message is too long for storing it in session */ + $this->logger->write_message("success", "Updated " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $data_number) . " [id:" . $voucher_id . "]"); + + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + return; + } + + function delete($voucher_type, $voucher_id = 0) + { + /* Check access */ + if ( ! check_access('delete voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('voucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + $this->db->trans_start(); + if ( ! $this->db->delete('voucher_items', array('voucher_id' => $voucher_id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting Voucher - Ledger A/C's.', 'error'); + $this->logger->write_message("error", "Error deleting ledger entries for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + redirect('voucher/view/' . $current_voucher_type['label'] . '/' . $voucher_id); + return; + } + if ( ! $this->db->delete('vouchers', array('id' => $voucher_id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting Voucher entry.', 'error'); + $this->logger->write_message("error", "Error deleting Voucher entry for " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + redirect('voucher/view/' . $current_voucher_type['label'] . '/' . $voucher_id); + return; + } + $this->db->trans_complete(); + $this->messages->add('Deleted ' . $current_voucher_type['name'] . ' Voucher.', 'success'); + $this->logger->write_message("success", "Deleted " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + function download($voucher_type, $voucher_id = 0) + { + $this->load->helper('download'); + $this->load->model('Setting_model'); + $this->load->model('Ledger_model'); + + /* Check access */ + if ( ! check_access('download voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + $data['voucher_number'] = $cur_voucher->number; + $data['voucher_date'] = date_mysql_to_php_display($cur_voucher->date); + $data['voucher_dr_total'] = $cur_voucher->dr_total; + $data['voucher_cr_total'] = $cur_voucher->cr_total; + $data['voucher_narration'] = $cur_voucher->narration; + + /* Getting Ledger details */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->order_by('dc', 'desc'); + $ledger_q = $this->db->get(); + $counter = 0; + $data['ledger_data'] = array(); + if ($ledger_q->num_rows() > 0) + { + foreach ($ledger_q->result() as $row) + { + $data['ledger_data'][$counter] = array( + 'id' => $row->ledger_id, + 'name' => $this->Ledger_model->get_name($row->ledger_id), + 'dc' => $row->dc, + 'amount' => $row->amount, + ); + $counter++; + } + } + + /* Download Voucher */ + $file_name = $current_voucher_type['name'] . '_voucher_' . $cur_voucher->number . ".html"; + $download_data = $this->load->view('voucher/downloadpreview', $data, TRUE); + force_download($file_name, $download_data); + return; + } + + function printpreview($voucher_type, $voucher_id = 0) + { + $this->load->model('Setting_model'); + $this->load->model('Ledger_model'); + + /* Check access */ + if ( ! check_access('print voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + $data['voucher_number'] = $cur_voucher->number; + $data['voucher_date'] = date_mysql_to_php_display($cur_voucher->date); + $data['voucher_dr_total'] = $cur_voucher->dr_total; + $data['voucher_cr_total'] = $cur_voucher->cr_total; + $data['voucher_narration'] = $cur_voucher->narration; + + /* Getting Ledger details */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->order_by('dc', 'desc'); + $ledger_q = $this->db->get(); + $counter = 0; + $data['ledger_data'] = array(); + if ($ledger_q->num_rows() > 0) + { + foreach ($ledger_q->result() as $row) + { + $data['ledger_data'][$counter] = array( + 'id' => $row->ledger_id, + 'name' => $this->Ledger_model->get_name($row->ledger_id), + 'dc' => $row->dc, + 'amount' => $row->amount, + ); + $counter++; + } + } + + $this->load->view('voucher/printpreview', $data); + return; + } + + function email($voucher_type, $voucher_id = 0) + { + $this->load->model('Setting_model'); + $this->load->model('Ledger_model'); + $this->load->library('email'); + + /* Check access */ + if ( ! check_access('email voucher')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/stockvoucher/show/' . $voucher_type); + return; + } + + /* Voucher Type */ + $voucher_type_id = voucher_type_name_to_id($voucher_type); + if ( ! $voucher_type_id) + { + $this->messages->add('Invalid Voucher type.', 'error'); + redirect('voucher/show/all'); + return; + } else { + $current_voucher_type = voucher_type_info($voucher_type_id); + } + + $account_data = $this->Setting_model->get_current(); + + /* Load current voucher details */ + if ( ! $cur_voucher = $this->Voucher_model->get_voucher($voucher_id, $voucher_type_id)) + { + $this->messages->add('Invalid Voucher.', 'error'); + redirect('voucher/show/' . $current_voucher_type['label']); + return; + } + + $data['voucher_type_id'] = $voucher_type_id; + $data['current_voucher_type'] = $current_voucher_type; + $data['voucher_id'] = $voucher_id; + $data['voucher_number'] = $cur_voucher->number; + $data['email_to'] = array( + 'name' => 'email_to', + 'id' => 'email_to', + 'size' => '40', + 'value' => '', + ); + + /* Form validations */ + $this->form_validation->set_rules('email_to', 'Email to', 'trim|valid_emails|required'); + + /* Repopulating form */ + if ($_POST) + { + $data['email_to']['value'] = $this->input->post('email_to', TRUE); + } + + if ($this->form_validation->run() == FALSE) + { + $data['error'] = validation_errors(); + $this->load->view('voucher/email', $data); + return; + } + else + { + $voucher_data['voucher_type_id'] = $voucher_type_id; + $voucher_data['current_voucher_type'] = $current_voucher_type; + $voucher_data['voucher_number'] = $cur_voucher->number; + $voucher_data['voucher_date'] = date_mysql_to_php_display($cur_voucher->date); + $voucher_data['voucher_dr_total'] = $cur_voucher->dr_total; + $voucher_data['voucher_cr_total'] = $cur_voucher->cr_total; + $voucher_data['voucher_narration'] = $cur_voucher->narration; + + /* Getting Ledger details */ + $this->db->from('voucher_items')->where('voucher_id', $voucher_id)->order_by('dc', 'desc'); + $ledger_q = $this->db->get(); + $counter = 0; + $voucher_data['ledger_data'] = array(); + if ($ledger_q->num_rows() > 0) + { + foreach ($ledger_q->result() as $row) + { + $voucher_data['ledger_data'][$counter] = array( + 'id' => $row->ledger_id, + 'name' => $this->Ledger_model->get_name($row->ledger_id), + 'dc' => $row->dc, + 'amount' => $row->amount, + ); + $counter++; + } + } + + /* Preparing message */ + $message = $this->load->view('voucher/emailpreview', $voucher_data, TRUE); + + /* Getting email configuration */ + $config['smtp_timeout'] = '30'; + $config['charset'] = 'utf-8'; + $config['newline'] = "\r\n"; + $config['mailtype'] = "html"; + if ($account_data) + { + $config['protocol'] = $account_data->email_protocol; + $config['smtp_host'] = $account_data->email_host; + $config['smtp_port'] = $account_data->email_port; + $config['smtp_user'] = $account_data->email_username; + $config['smtp_pass'] = $account_data->email_password; + } else { + $data['error'] = 'Invalid account settings.'; + } + $this->email->initialize($config); + + /* Sending email */ + $this->email->from('', 'Webzash'); + $this->email->to($this->input->post('email_to', TRUE)); + $this->email->subject($current_voucher_type['name'] . ' Voucher No. ' . full_voucher_number($voucher_type_id, $cur_voucher->number)); + $this->email->message($message); + if ($this->email->send()) + { + $data['message'] = "Email sent."; + $this->logger->write_message("success", "Emailed " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + } else { + $data['error'] = "Error sending email. Check you email settings."; + $this->logger->write_message("error", "Error emailing " . $current_voucher_type['name'] . " Voucher number " . full_voucher_number($voucher_type_id, $cur_voucher->number) . " [id:" . $voucher_id . "]"); + } + $this->load->view('voucher/email', $data); + return; + } + return; + } + + function addstockrow() + { + $i = time() + rand (0, time()) + rand (0, time()) + rand (0, time()); + $stock_item_quantity = array( + 'name' => 'stock_item_quantity[' . $i . ']', + 'id' => 'stock_item_quantity[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => '', + 'class' => 'quantity-item', + ); + $stock_item_rate_per_unit = array( + 'name' => 'stock_item_rate_per_unit[' . $i . ']', + 'id' => 'stock_item_rate_per_unit[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => '', + 'class' => 'rate-item', + ); + $stock_item_amount = array( + 'name' => 'stock_item_amount[' . $i . ']', + 'id' => 'stock_item_amount[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => '', + 'class' => 'rate-item', + ); + + echo '<tr class="new-row">'; + echo "<td>" . form_input_stock_item('stock_item_id[' . $i . ']', 0) . "</td>"; + echo "<td>" . form_input($stock_item_quantity) . "</td>"; + echo "<td>" . form_input($stock_item_rate_per_unit) . "</td>"; + echo "<td>" . form_input($stock_item_amount) . "</td>"; + echo '<td>'; + echo img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Stock Item', 'class' => 'addstockrow')); + echo '</td>'; + echo '<td>'; + echo img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Stock Item', 'class' => 'deletestockrow')); + echo '</td>'; + echo '<td class="stock-item-balance"><div></div>'; + echo '</td>'; + echo '</tr>'; + return; + } +} + +/* End of file voucher.php */ +/* Location: ./system/application/controllers/voucher.php */ diff --git a/system/application/controllers/voucher.php b/system/application/controllers/voucher.php index 7db9777..eda8357 100644 --- a/system/application/controllers/voucher.php +++ b/system/application/controllers/voucher.php @@ -49,7 +49,10 @@ class Voucher extends Controller { } else { $current_voucher_type = voucher_type_info($voucher_type_id); $this->template->set('page_title', $current_voucher_type['name'] . ' Vouchers'); - $this->template->set('nav_links', array('voucher/add/' . $current_voucher_type['label'] => 'New ' . $current_voucher_type['name'] . ' Voucher')); + if ($current_voucher_type['base_type'] == '1') + $this->template->set('nav_links', array('voucher/add/' . $current_voucher_type['label'] => 'New ' . $current_voucher_type['name'] . ' Voucher')); + else + $this->template->set('nav_links', array('inventory/stockvoucher/add/' . $current_voucher_type['label'] => 'New ' . $current_voucher_type['name'] . ' Voucher')); } }
diff --git a/system/application/helpers/MY_form_helper.php b/system/application/helpers/MY_form_helper.php index 786a38c..cdc5825 100644 --- a/system/application/helpers/MY_form_helper.php +++ b/system/application/helpers/MY_form_helper.php @@ -66,6 +66,10 @@ if ( ! function_exists('form_input_ledger')) $options = $CI->Ledger_model->get_all_ledgers_nobankcash(); else if ($type == 'reconciliation') $options = $CI->Ledger_model->get_all_ledgers_reconciliation(); + else if ($type == 'purchase') + $options = $CI->Ledger_model->get_all_ledgers_purchase(); + else if ($type == 'creditor') + $options = $CI->Ledger_model->get_all_ledgers_creditor(); else $options = $CI->Ledger_model->get_all_ledgers();
@@ -96,5 +100,41 @@ if ( ! function_exists('form_input_ledger')) } }
+if ( ! function_exists('form_input_stock_item')) +{ + function form_input_stock_item($name, $selected = NULL, $extra = '') + { + $CI =& get_instance(); + $CI->load->model('Stock_Item_model'); + + $options = $CI->Stock_Item_model->get_all_item(); + + // If no selected state was submitted we will attempt to set it automatically + if ( ! ($selected)) + { + // If the form name appears in the $_POST array we have a winner! + if (isset($_POST[$name])) + { + $selected = $_POST[$name]; + } + } + + if ($extra != '') $extra = ' '.$extra; + + $form = '<select name="'.$name.'"'.$extra.' class="stock-item-dropdown">'; + + foreach ($options as $key => $val) + { + $key = (string) $key; + $sel = ($key == $selected) ? ' selected="selected"' : ''; + $form .= '<option value="'.$key.'"'.$sel.'>'.(string) $val."</option>\n"; + } + + $form .= '</select>'; + + return $form; + } +} + /* End of file MY_form_helper.php */ /* Location: ./system/application/helpers/MY_form_helper.php */ diff --git a/system/application/helpers/access_helper.php b/system/application/helpers/access_helper.php index 35e7067..9498dee 100644 --- a/system/application/helpers/access_helper.php +++ b/system/application/helpers/access_helper.php @@ -13,6 +13,13 @@ * 'print voucher' * 'email voucher' * 'download voucher' + * 'view stock voucher' + * 'create stock voucher' + * 'edit stock voucher' + * 'delete stock voucher' + * 'print stock voucher' + * 'email stock voucher' + * 'download stock voucher' * 'create ledger' * 'edit ledger' * 'delete ledger' @@ -25,6 +32,9 @@ * 'create stock group' * 'edit stock group' * 'delete stock group' + * 'create stock item', + * 'edit stock item', + * 'delete stock item', * 'create tag' * 'edit tag' * 'delete tag' @@ -51,6 +61,13 @@ if ( ! function_exists('check_access')) 'print voucher', 'email voucher', 'download voucher', + 'view stock voucher', + 'create stock voucher', + 'edit stock voucher', + 'delete stock voucher', + 'print stock voucher', + 'email stock voucher', + 'download stock voucher', 'create ledger', 'edit ledger', 'delete ledger', @@ -63,6 +80,9 @@ if ( ! function_exists('check_access')) 'create stock group', 'edit stock group', 'delete stock group', + 'create stock item', + 'edit stock item', + 'delete stock item', 'create tag', 'edit tag', 'delete tag', @@ -81,6 +101,13 @@ if ( ! function_exists('check_access')) 'print voucher', 'email voucher', 'download voucher', + 'view stock voucher', + 'create stock voucher', + 'edit stock voucher', + 'delete stock voucher', + 'print stock voucher', + 'email stock voucher', + 'download stock voucher', 'create ledger', 'edit ledger', 'delete ledger', @@ -93,6 +120,9 @@ if ( ! function_exists('check_access')) 'create stock group', 'edit stock group', 'delete stock group', + 'create stock item', + 'edit stock item', + 'delete stock item', 'create tag', 'edit tag', 'delete tag', @@ -108,8 +138,17 @@ if ( ! function_exists('check_access')) 'print voucher', 'email voucher', 'download voucher', + 'view stock voucher', + 'create stock voucher', + 'edit stock voucher', + 'delete stock voucher', + 'print stock voucher', + 'email stock voucher', + 'download stock voucher', 'create ledger', 'edit ledger', + 'create stock item', + 'edit stock item', ); $permissions['guest'] = array( 'view voucher', diff --git a/system/application/helpers/custom_helper.php b/system/application/helpers/custom_helper.php index de31de7..15b3029 100644 --- a/system/application/helpers/custom_helper.php +++ b/system/application/helpers/custom_helper.php @@ -116,6 +116,7 @@ if ( ! function_exists('voucher_type_info')) 'id' => $voucher_type_all[$voucher_type_id], 'label' => $voucher_type_all[$voucher_type_id]['label'], 'name' => $voucher_type_all[$voucher_type_id]['name'], + 'base_type' => $voucher_type_all[$voucher_type_id]['base_type'], 'numbering' => $voucher_type_all[$voucher_type_id]['numbering'], 'prefix' => $voucher_type_all[$voucher_type_id]['prefix'], 'suffix' => $voucher_type_all[$voucher_type_id]['suffix'], @@ -127,6 +128,7 @@ if ( ! function_exists('voucher_type_info')) 'id' => $voucher_type_all[$voucher_type_id], 'label' => '', 'name' => '(Unkonwn)', + 'base_type' => 1, 'numbering' => 1, 'prefix' => '', 'suffix' => '', diff --git a/system/application/models/ledger_model.php b/system/application/models/ledger_model.php index 71f36f5..d50bcbe 100644 --- a/system/application/models/ledger_model.php +++ b/system/application/models/ledger_model.php @@ -59,6 +59,32 @@ class Ledger_model extends Model { return $options; }
+ function get_all_ledgers_purchase() + { + $options = array(); + $options[0] = "(Please Select)"; + $this->db->from('ledgers')->where('type', 2)->order_by('name', 'asc'); + $ledger_q = $this->db->get(); + foreach ($ledger_q->result() as $row) + { + $options[$row->id] = $row->name; + } + return $options; + } + + function get_all_ledgers_creditor() + { + $options = array(); + $options[0] = "(Please Select)"; + $this->db->from('ledgers')->where('type', 5)->order_by('name', 'asc'); + $ledger_q = $this->db->get(); + foreach ($ledger_q->result() as $row) + { + $options[$row->id] = $row->name; + } + return $options; + } + function get_name($ledger_id) { $this->db->from('ledgers')->where('id', $ledger_id)->limit(1); diff --git a/system/application/models/stock_item_model.php b/system/application/models/stock_item_model.php index da33e9f..1b4ae88 100644 --- a/system/application/models/stock_item_model.php +++ b/system/application/models/stock_item_model.php @@ -29,4 +29,9 @@ class Stock_Item_model extends Model { else return "(Error)"; } + + function get_stock_item_balance($stock_item_id) + { + return '100'; + } } diff --git a/system/application/views/inventory/stockvoucher/add.php b/system/application/views/inventory/stockvoucher/add.php new file mode 100644 index 0000000..83a68bc --- /dev/null +++ b/system/application/views/inventory/stockvoucher/add.php @@ -0,0 +1,313 @@ +<?php + /* Add row ledger type */ + $add_type = "all"; +?> +<script type="text/javascript"> + +$(document).ready(function() { + + /***************************** STOCK ITEM *****************************/ + /* Stock Item dropdown changed */ + $('.stock-item-dropdown').live('change', function() { + if ($(this).val() == "0") { + $(this).parent().next().children().attr('value', ""); + $(this).parent().next().next().children().attr('value', ""); + $(this).parent().next().next().next().children().attr('value', ""); + $(this).parent().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().next().children().attr('disabled', 'disabled'); + } else { + $(this).parent().next().children().attr('disabled', ''); + $(this).parent().next().next().children().attr('disabled', ''); + $(this).parent().next().next().next().children().attr('disabled', ''); + $(this).parent().prev().children().trigger('change'); + } + var stockid = $(this).val(); + var rowid = $(this); + if (stockid > 0) { + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockitem/balance') . '/\''; ?> + stockid, + success: function(data) { + var stock_bal = parseFloat(data); + if (isNaN(stock_bal)) + stock_bal = 0; + if (stock_bal == 0) + rowid.parent().next().next().next().next().next().children().text("0"); + else if (stock_bal < 0) + rowid.parent().next().next().next().next().next().next().children().text(data); + else + rowid.parent().next().next().next().next().next().next().children().text(data); + } + }); + } else { + rowid.parent().next().next().next().next().next().next().children().text(""); + } + }); + + $('table td .quantity-item').live('change', function() { + var rowid = $(this); + calculateRowTotal(rowid.parent().prev()); + }); + + var calculateRowTotal = function(itemrow) { + var item_quantity = itemrow.next().children().val(); + var item_rate_per_unit = itemrow.next().next().children().val(); + var item_amount = itemrow.next().next().next().children().val(); + + item_quantity = parseFloat(item_quantity); + item_rate_per_unit = parseFloat(item_rate_per_unit); + if ( (!isNaN(item_quantity)) && (!isNaN(item_rate_per_unit)) ) + { + item_amount = item_quantity * item_rate_per_unit; + itemrow.next().next().next().children().val(item_amount); + itemrow.next().next().next().fadeTo('slow', 0.1).fadeTo('slow', 1); + } + } + + /* Add stock item row */ + $('table td .addstockrow').live('click', function() { + var cur_obj = this; + var add_image_url = $(cur_obj).attr('src'); + $(cur_obj).attr('src', <?php echo '\'' . asset_url() . 'images/icons/ajax.gif' . '\''; ?>); + $.ajax({ + url: <?php echo '\'' . site_url('inventory/stockvoucher/addstockrow') . '\''; ?>, + success: function(data) { + $(cur_obj).parent().parent().after(data); + $(cur_obj).attr('src', add_image_url); + $('.stock-item-dropdown').trigger('change'); + } + }); + }); + + /* Delete stock item row */ + $('table td .deletestockrow').live('click', function() { + $(this).parent().parent().remove(); + }); + + /******************************* LEDGER *******************************/ + /* Dr - Cr dropdown changed */ + $('.dc-dropdown').live('change', function() { + }); + + /* Ledger dropdown changed */ + $('.ledger-dropdown').live('change', function() { + if ($(this).val() == "0") { + $(this).parent().next().children().attr('value', ""); + $(this).parent().next().next().children().attr('value', ""); + $(this).parent().next().children().attr('disabled', 'disabled'); + $(this).parent().next().next().children().attr('disabled', 'disabled'); + } else { + $(this).parent().next().children().attr('disabled', ''); + $(this).parent().next().next().children().attr('disabled', ''); + $(this).parent().prev().children().trigger('change'); + } + $(this).parent().next().children().trigger('change'); + $(this).parent().next().next().children().trigger('change'); + + var ledgerid = $(this).val(); + var rowid = $(this); + if (ledgerid > 0) { + $.ajax({ + url: <?php echo '\'' . site_url('ledger/balance') . '/\''; ?> + ledgerid, + success: function(data) { + var ledger_bal = parseFloat(data); + if (isNaN(ledger_bal)) + ledger_bal = 0; + if (ledger_bal == 0) + rowid.parent().next().next().next().next().next().children().text("0"); + else if (ledger_bal < 0) + rowid.parent().next().next().next().next().next().children().text("Cr " + -data); + else + rowid.parent().next().next().next().next().next().children().text("Dr " + data); + } + }); + } else { + rowid.parent().next().next().next().next().next().children().text(""); + } + }); + + /* Recalculate Total */ + $('table td .recalculate').live('click', function() { + + }); + + /* Delete ledger row */ + $('table td .deleterow').live('click', function() { + $(this).parent().parent().remove(); + }); + + /* Add ledger row */ + $('table td .addrow').live('click', function() { + var cur_obj = this; + var add_image_url = $(cur_obj).attr('src'); + $(cur_obj).attr('src', <?php echo '\'' . asset_url() . 'images/icons/ajax.gif' . '\''; ?>); + $.ajax({ + url: <?php echo '\'' . site_url('voucher/addrow/' . $add_type) . '\''; ?>, + success: function(data) { + $(cur_obj).parent().parent().after(data); + $(cur_obj).attr('src', add_image_url); + } + }); + }); + + /* On page load initiate all triggers */ + $('.dc-dropdown').trigger('change'); + $('.ledger-dropdown').trigger('change'); + $('.stock-item-dropdown').trigger('change'); +}); + +</script> + +<?php + echo form_open('voucher/add/' . $current_voucher_type['label']); + echo "<p>"; + echo "<span id="tooltip-target-1">"; + echo form_label('Voucher Number', 'voucher_number'); + echo " "; + echo $current_voucher_type['prefix'] . form_input($voucher_number) . $current_voucher_type['suffix']; + echo "</span>"; + echo "<span id="tooltip-content-1">Leave Voucher Number empty for auto numbering</span>"; + echo " "; + echo "<span id="tooltip-target-2">"; + echo form_label('Voucher Date', 'voucher_date'); + echo " "; + echo form_input_date_restrict($voucher_date); + echo "</span>"; + echo "<span id="tooltip-content-2">Date format is " . $this->config->item('account_date_format') . ".</span>"; + echo "</p>"; + + echo "<p>"; + echo "<table border=0 cellpadding=2>"; + echo "<tr>"; + echo "<td align="right">"; + echo form_label('Purchase Ledger A/C', 'purchase_ledger_id'); + echo "</td>"; + echo "<td>"; + echo form_input_ledger('purchase_ledger_id', '', '', $type = 'purchase'); + echo "</td>"; + echo "</tr>"; + + echo "<tr>"; + echo "<td align="right">"; + echo form_label('Creditor (Supplier)', 'creditor_ledger_id'); + echo "</td>"; + echo "<td>"; + echo form_input_ledger('creditor_ledger_id', '', '', $type = 'creditor'); + echo "</td>"; + echo "</tr>"; + echo "</table>"; + echo "</p>"; + + echo "<p></p>"; + + echo "<table class="voucher-table">"; + echo "<thead><tr><th>Stock Item</th><th>Quantity</th><th>Rate Per Unit</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + + foreach ($stock_item_id as $i => $row) + { + $stock_item_quantity = array( + 'name' => 'stock_item_quantity[' . $i . ']', + 'id' => 'stock_item_quantity[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => '', + 'class' => 'quantity-item', + ); + $stock_item_rate_per_unit = array( + 'name' => 'stock_item_rate_per_unit[' . $i . ']', + 'id' => 'stock_item_rate_per_unit[' . $i . ']', + 'maxlength' => '15', + 'size' => '9', + 'value' => '', + 'class' => 'rate-item', + ); + $stock_item_amount = array( + 'name' => 'stock_item_amount[' . $i . ']', + 'id' => 'stock_item_amount[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => '', + 'class' => 'rate-item', + ); + echo "<tr>"; + + echo "<td>" . form_input_stock_item('stock_item_id[' . $i . ']', 0) . "</td>"; + echo "<td>" . form_input($stock_item_quantity) . "</td>"; + echo "<td>" . form_input($stock_item_rate_per_unit) . "</td>"; + echo "<td>" . form_input($stock_item_amount) . "</td>"; + + echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addstockrow')) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deletestockrow')) . "</td>"; + + echo "<td class="stock-item-balance"><div></div></td>"; + + echo "</tr>"; + } + echo "</table>"; + + echo "<br />"; + echo "<br />"; + + echo "<table class="voucher-table">"; + echo "<thead><tr><th>Type</th><th>Ledger A/C</th><th>Rate</th><th>Amount</th><th colspan=2></th><th colspan=2>Cur Balance</th></tr></thead>"; + + foreach ($ledger_dc as $i => $ledger) + { + $rate_item = array( + 'name' => 'rate_item[' . $i . ']', + 'id' => 'rate_item[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => isset($dr_amount[$i]) ? $dr_amount[$i] : "", + 'class' => 'dr-item', + ); + $amount_item = array( + 'name' => 'amount_item[' . $i . ']', + 'id' => 'amount_item[' . $i . ']', + 'maxlength' => '15', + 'size' => '15', + 'value' => isset($cr_amount[$i]) ? $cr_amount[$i] : "", + 'class' => 'cr-item', + ); + echo "<tr>"; + + echo "<td>" . form_dropdown_dc('ledger_dc[' . $i . ']', isset($ledger_dc[$i]) ? $ledger_dc[$i] : "D") . "</td>"; + + echo "<td>" . form_input_ledger('ledger_id[' . $i . ']', isset($ledger_id[$i]) ? $ledger_id[$i] : 0) . "</td>"; + + echo "<td>" . form_input($rate_item) . "</td>"; + echo "<td>" . form_input($amount_item) . "</td>"; + + echo "<td>" . img(array('src' => asset_url() . "images/icons/add.png", 'border' => '0', 'alt' => 'Add Ledger', 'class' => 'addrow')) . "</td>"; + echo "<td>" . img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Remove Ledger', 'class' => 'deleterow')) . "</td>"; + + echo "<td class="ledger-balance"><div></div></td>"; + + echo "</tr>"; + } + + echo "<tr><td colspan="7"></td></tr>"; + echo "<tr id="voucher-total"><td colspan=3><strong>Total</strong></td><td id="cr-total">0</td><td>" . img(array('src' => asset_url() . "images/icons/gear.png", 'border' => '0', 'alt' => 'Recalculate Total', 'class' => 'recalculate', 'title' => 'Recalculate Total')) . "</td><td></td><td></td></tr>"; + + echo "</table>"; + + echo "<p>"; + echo form_label('Narration', 'voucher_narration'); + echo "<br />"; + echo form_textarea($voucher_narration); + echo "</p>"; + + echo "<p>"; + echo form_label('Tag', 'voucher_tag'); + echo " "; + echo form_dropdown('voucher_tag', $voucher_tags, $voucher_tag); + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Create'); + echo " "; + echo anchor('voucher/show/' . $current_voucher_type['label'], 'Back', array('title' => 'Back to ' . $current_voucher_type['name'] . ' Vouchers')); + echo "</p>"; + + echo form_close(); +
commit 2e042a681f030e4ac46d8082be5aacdb764febc0 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sun Feb 6 16:07:44 2011 +0530
Added inventory options to Ledger A/C
- Updated Ledger A/C type from CHAR(1) to INT(2) - Added inventory options to Ledger A/C add/edit actions
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/db-update.txt b/db-update.txt index 83856c3..60f62b7 100644 --- a/db-update.txt +++ b/db-update.txt @@ -1,5 +1,10 @@ //--------------------------------- VERSION 4 ----------------------------------
+UPDATE ledgers SET type = '1' WHERE type = 'B'; +UPDATE ledgers SET type = '0' WHERE type = 'N'; + +ALTER TABLE ledgers CHANGE type type INT(2) NOT NULL DEFAULT '0'; + CREATE TABLE IF NOT EXISTS stock_units ( id int(11) NOT NULL AUTO_INCREMENT, symbol varchar(15) NOT NULL, diff --git a/system/application/controllers/admin/schema.sql b/system/application/controllers/admin/schema.sql index c2f3461..6e4d706 100644 --- a/system/application/controllers/admin/schema.sql +++ b/system/application/controllers/admin/schema.sql @@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS ledgers ( name varchar(100) NOT NULL, op_balance decimal(15,2) NOT NULL DEFAULT '0.00', op_balance_dc char(1) NOT NULL, - type char(1) NOT NULL, + type int(2) NOT NULL DEFAULT '0', reconciliation int(1) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=1; diff --git a/system/application/controllers/ledger.php b/system/application/controllers/ledger.php index 7403867..bff86cf 100644 --- a/system/application/controllers/ledger.php +++ b/system/application/controllers/ledger.php @@ -57,6 +57,16 @@ class Ledger extends Controller { $data['ledger_type_cashbank'] = FALSE; $data['reconciliation'] = FALSE;
+ /**** Inventory ***/ + $data['affects_inventory'] = 0; + $data['affects_inventory_options'] = array( + '2' => 'Purchases Ledger A/C', + '3' => 'Sales Ledger A/C', + '4' => 'Debtor (Customer)', + '5' => 'Creditor (Supplier)', + ); + $data['affects_inventory_option_active'] = '2'; + /* Form validations */ $this->form_validation->set_rules('ledger_name', 'Ledger name', 'trim|required|min_length[2]|max_length[100]|unique[ledgers.name]'); $this->form_validation->set_rules('ledger_group_id', 'Parent group', 'trim|required|is_natural_no_zero'); @@ -72,6 +82,10 @@ class Ledger extends Controller { $data['op_balance_dc'] = $this->input->post('op_balance_dc', TRUE); $data['ledger_type_cashbank'] = $this->input->post('ledger_type_cashbank', TRUE); $data['reconciliation'] = $this->input->post('reconciliation', TRUE); + + /**** Inventory ***/ + $data['affects_inventory'] = $this->input->post('affects_inventory', TRUE); + $data['affects_inventory_option_active'] = $this->input->post('affects_inventory_option', TRUE); }
if ($this->form_validation->run() == FALSE) @@ -86,9 +100,14 @@ class Ledger extends Controller { $data_group_id = $this->input->post('ledger_group_id', TRUE); $data_op_balance = $this->input->post('op_balance', TRUE); $data_op_balance_dc = $this->input->post('op_balance_dc', TRUE); + $data_ledger_type = 0; $data_ledger_type_cashbank_value = $this->input->post('ledger_type_cashbank', TRUE); $data_reconciliation = $this->input->post('reconciliation', TRUE);
+ /**** Inventory ***/ + $data_affects_inventory = $this->input->post('affects_inventory', TRUE); + $data_affects_inventory_option_active = $this->input->post('affects_inventory_option', TRUE); + if ($data_group_id < 5) { $this->messages->add('Invalid Parent group.', 'error'); @@ -107,9 +126,9 @@ class Ledger extends Controller {
if ($data_ledger_type_cashbank_value == "1") { - $data_ledger_type_cashbank = "B"; + $data_ledger_type = 1; } else { - $data_ledger_type_cashbank = "N"; + $data_ledger_type = 0; }
if ($data_reconciliation == "1") @@ -119,13 +138,25 @@ class Ledger extends Controller { $data_reconciliation = 0; }
+ /**** Inventory ***/ + if ($data_affects_inventory == "1") + { + if (($data_affects_inventory_option_active < 2) or ($data_affects_inventory_option_active > 5)) + { + $this->messages->add('Invalid inventory option selected.', 'error'); + $this->template->load('template', 'ledger/add', $data); + return; + } + $data_ledger_type = $data_affects_inventory_option_active; + } + $this->db->trans_start(); $insert_data = array( 'name' => $data_name, 'group_id' => $data_group_id, 'op_balance' => $data_op_balance, 'op_balance_dc' => $data_op_balance_dc, - 'type' => $data_ledger_type_cashbank, + 'type' => $data_ledger_type, 'reconciliation' => $data_reconciliation, ); if ( ! $this->db->insert('ledgers', $insert_data)) @@ -206,12 +237,34 @@ class Ledger extends Controller { $data['ledger_group_active'] = $ledger_data->group_id; $data['op_balance_dc'] = $ledger_data->op_balance_dc; $data['ledger_id'] = $id; - if ($ledger_data->type == "B") - $data['ledger_type_cashbank'] = TRUE; - else - $data['ledger_type_cashbank'] = FALSE; $data['reconciliation'] = $ledger_data->reconciliation;
+ /**** Inventory ***/ + $data['affects_inventory_options'] = array( + '2' => 'Purchases Ledger A/C', + '3' => 'Sales Ledger A/C', + '4' => 'Debtor (Customer)', + '5' => 'Creditor (Supplier)', + ); + if ($ledger_data->type <= 0) + { + $data['ledger_type_cashbank'] = 0; + $data['affects_inventory'] = 0; + $data['affects_inventory_option_active'] = 2; + } else if ($ledger_data->type == 1) { + $data['ledger_type_cashbank'] = 1; + $data['affects_inventory'] = 0; + $data['affects_inventory_option_active'] = 2; + } else if (($ledger_data->type > 1) and ($ledger_data->type < 6)) { + $data['ledger_type_cashbank'] = 0; + $data['affects_inventory'] = 1; + $data['affects_inventory_option_active'] = $ledger_data->type; + } else { + $data['ledger_type_cashbank'] = 0; + $data['affects_inventory'] = 0; + $data['affects_inventory_option_active'] = 2; + } + /* Form validations */ $this->form_validation->set_rules('ledger_name', 'Ledger name', 'trim|required|min_length[2]|max_length[100]|uniquewithid[ledgers.name.' . $id . ']'); $this->form_validation->set_rules('ledger_group_id', 'Parent group', 'trim|required|is_natural_no_zero'); @@ -227,6 +280,10 @@ class Ledger extends Controller { $data['op_balance_dc'] = $this->input->post('op_balance_dc', TRUE); $data['ledger_type_cashbank'] = $this->input->post('ledger_type_cashbank', TRUE); $data['reconciliation'] = $this->input->post('reconciliation', TRUE); + + /**** Inventory ***/ + $data['affects_inventory'] = $this->input->post('affects_inventory', TRUE); + $data['affects_inventory_option_active'] = $this->input->post('affects_inventory_option', TRUE); }
if ($this->form_validation->run() == FALSE) @@ -241,9 +298,14 @@ class Ledger extends Controller { $data_group_id = $this->input->post('ledger_group_id', TRUE); $data_op_balance = $this->input->post('op_balance', TRUE); $data_op_balance_dc = $this->input->post('op_balance_dc', TRUE); - $data_id = $id; + $data_ledger_type = 0; $data_ledger_type_cashbank_value = $this->input->post('ledger_type_cashbank', TRUE); $data_reconciliation = $this->input->post('reconciliation', TRUE); + $data_id = $id; + + /**** Inventory ***/ + $data_affects_inventory = $this->input->post('affects_inventory', TRUE); + $data_affects_inventory_option_active = $this->input->post('affects_inventory_option', TRUE);
if ($data_group_id < 5) { @@ -284,9 +346,9 @@ class Ledger extends Controller {
if ($data_ledger_type_cashbank_value == "1") { - $data_ledger_type_cashbank = "B"; + $data_ledger_type = 1; } else { - $data_ledger_type_cashbank = "N"; + $data_ledger_type = 0; }
if ($data_reconciliation == "1") @@ -296,13 +358,25 @@ class Ledger extends Controller { $data_reconciliation = 0; }
+ /**** Inventory ***/ + if ($data_affects_inventory == "1") + { + if (($data_affects_inventory_option_active < 2) or ($data_affects_inventory_option_active > 5)) + { + $this->messages->add('Invalid inventory option selected.', 'error'); + $this->template->load('template', 'ledger/edit', $data); + return; + } + $data_ledger_type = $data_affects_inventory_option_active; + } + $this->db->trans_start(); $update_data = array( 'name' => $data_name, 'group_id' => $data_group_id, 'op_balance' => $data_op_balance, 'op_balance_dc' => $data_op_balance_dc, - 'type' => $data_ledger_type_cashbank, + 'type' => $data_ledger_type, 'reconciliation' => $data_reconciliation, ); if ( ! $this->db->where('id', $data_id)->update('ledgers', $update_data)) diff --git a/system/application/controllers/voucher.php b/system/application/controllers/voucher.php index cd71753..7db9777 100644 --- a/system/application/controllers/voucher.php +++ b/system/application/controllers/voucher.php @@ -358,23 +358,23 @@ class Voucher extends Controller { $valid_ledger = $valid_ledger_q->row(); if ($current_voucher_type['bank_cash_ledger_restriction'] == '2') { - if ($data_all_ledger_dc[$id] == 'D' && $valid_ledger->type == 'B') + if ($data_all_ledger_dc[$id] == 'D' && $valid_ledger->type == 1) { $bank_cash_present = TRUE; } - if ($valid_ledger->type != 'B') + if ($valid_ledger->type != 1) $non_bank_cash_present = TRUE; } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') { - if ($data_all_ledger_dc[$id] == 'C' && $valid_ledger->type == 'B') + if ($data_all_ledger_dc[$id] == 'C' && $valid_ledger->type == 1) { $bank_cash_present = TRUE; } - if ($valid_ledger->type != 'B') + if ($valid_ledger->type != 1) $non_bank_cash_present = TRUE; } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '4') { - if ($valid_ledger->type != 'B') + if ($valid_ledger->type != 1) { $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers can have only Bank and Cash Ledgers A/C's.', 'error'); $this->template->load('template', 'voucher/add', $data); @@ -382,7 +382,7 @@ class Voucher extends Controller { } } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '5') { - if ($valid_ledger->type == 'B') + if ($valid_ledger->type == 1) { $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers cannot have Bank and Cash Ledgers A/C's.', 'error'); $this->template->load('template', 'voucher/add', $data); @@ -727,23 +727,23 @@ class Voucher extends Controller { $valid_ledger = $valid_ledger_q->row(); if ($current_voucher_type['bank_cash_ledger_restriction'] == '2') { - if ($data_all_ledger_dc[$id] == 'D' && $valid_ledger->type == 'B') + if ($data_all_ledger_dc[$id] == 'D' && $valid_ledger->type == 1) { $bank_cash_present = TRUE; } - if ($valid_ledger->type != 'B') + if ($valid_ledger->type != 1) $non_bank_cash_present = TRUE; } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '3') { - if ($data_all_ledger_dc[$id] == 'C' && $valid_ledger->type == 'B') + if ($data_all_ledger_dc[$id] == 'C' && $valid_ledger->type == 1) { $bank_cash_present = TRUE; } - if ($valid_ledger->type != 'B') + if ($valid_ledger->type != 1) $non_bank_cash_present = TRUE; } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '4') { - if ($valid_ledger->type != 'B') + if ($valid_ledger->type != 1) { $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers can have only Bank and Cash Ledgers A/C's.', 'error'); $this->template->load('template', 'voucher/edit', $data); @@ -751,7 +751,7 @@ class Voucher extends Controller { } } else if ($current_voucher_type['bank_cash_ledger_restriction'] == '5') { - if ($valid_ledger->type == 'B') + if ($valid_ledger->type == 1) { $this->messages->add('Invalid Ledger A/C. ' . $current_voucher_type['name'] . ' Vouchers cannot have Bank and Cash Ledgers A/C's.', 'error'); $this->template->load('template', 'voucher/edit', $data); diff --git a/system/application/controllers/welcome.php b/system/application/controllers/welcome.php index df0c301..8e3be2f 100644 --- a/system/application/controllers/welcome.php +++ b/system/application/controllers/welcome.php @@ -17,7 +17,7 @@ class Welcome extends Controller { $this->template->set('add_javascript', array("js/raphael.js", "js/jquery.enumerable.js", "js/jquery.tufte-graph.js"));
/* Bank and Cash Ledger accounts */ - $this->db->from('ledgers')->where('type', 'B'); + $this->db->from('ledgers')->where('type', 1); $bank_q = $this->db->get(); if ($bank_q->num_rows() > 0) { diff --git a/system/application/models/ledger_model.php b/system/application/models/ledger_model.php index fe7fd04..71f36f5 100644 --- a/system/application/models/ledger_model.php +++ b/system/application/models/ledger_model.php @@ -24,7 +24,7 @@ class Ledger_model extends Model { { $options = array(); $options[0] = "(Please Select)"; - $this->db->from('ledgers')->where('type', 'B')->order_by('name', 'asc'); + $this->db->from('ledgers')->where('type', 1)->order_by('name', 'asc'); $ledger_q = $this->db->get(); foreach ($ledger_q->result() as $row) { @@ -37,7 +37,7 @@ class Ledger_model extends Model { { $options = array(); $options[0] = "(Please Select)"; - $this->db->from('ledgers')->where('type !=', 'B')->order_by('name', 'asc'); + $this->db->from('ledgers')->where('type !=', 1)->order_by('name', 'asc'); $ledger_q = $this->db->get(); foreach ($ledger_q->result() as $row) { diff --git a/system/application/views/ledger/add.php b/system/application/views/ledger/add.php index b5c2ba6..d597041 100644 --- a/system/application/views/ledger/add.php +++ b/system/application/views/ledger/add.php @@ -32,6 +32,11 @@ echo "</p>";
echo "<p>"; + echo form_checkbox('affects_inventory', 1, $affects_inventory) . " Affects Inventory "; + echo form_dropdown('affects_inventory_option', $affects_inventory_options, $affects_inventory_option_active); + echo "</p>"; + + echo "<p>"; echo "<span id="tooltip-target-3">"; echo form_checkbox('reconciliation', 1, $reconciliation) . " Reconciliation"; echo "</span>"; diff --git a/system/application/views/ledger/edit.php b/system/application/views/ledger/edit.php index a9057c1..2801dcd 100644 --- a/system/application/views/ledger/edit.php +++ b/system/application/views/ledger/edit.php @@ -32,6 +32,11 @@ echo "</p>";
echo "<p>"; + echo form_checkbox('affects_inventory', 1, $affects_inventory) . " Affects Inventory "; + echo form_dropdown('affects_inventory_option', $affects_inventory_options, $affects_inventory_option_active); + echo "</p>"; + + echo "<p>"; echo "<span id="tooltip-target-3">"; echo form_checkbox('reconciliation', 1, $reconciliation) . " Reconciliation"; echo "</span>";
commit b71155dc177b8c74982469562a51846e0f415c15 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sat Feb 5 16:13:32 2011 +0530
Added the stock tree view
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/account.php b/system/application/controllers/inventory/account.php index 3201ef0..9043d30 100644 --- a/system/application/controllers/inventory/account.php +++ b/system/application/controllers/inventory/account.php @@ -10,6 +10,11 @@ class Account extends Controller { $this->db->from('stock_units')->order_by('name', 'desc'); $data['stock_units'] = $this->db->get();
+ /* Stocks Tree */ + $this->load->library('stockstree'); + $stocks_tree_o = new Stockstree(); + $data['stocks_tree'] = $stocks_tree_o->init(0); + $this->template->load('template', 'inventory/account/index', $data); return; } diff --git a/system/application/helpers/custom_helper.php b/system/application/helpers/custom_helper.php index 21f23a4..de31de7 100644 --- a/system/application/helpers/custom_helper.php +++ b/system/application/helpers/custom_helper.php @@ -36,7 +36,7 @@ if ( ! function_exists('convert_amount_dc')) { function convert_amount_dc($amount) { - if ($amount == "D") + if ($amount == "0") return "0"; else if ($amount < 0) return "Cr " . convert_cur(-$amount); diff --git a/system/application/libraries/Stockstree.php b/system/application/libraries/Stockstree.php new file mode 100644 index 0000000..f907989 --- /dev/null +++ b/system/application/libraries/Stockstree.php @@ -0,0 +1,139 @@ +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); + +class Stockstree +{ + public static $counter = 0; + + function Stockstree() + { + return; + } + + function init($start_id = 0) + { + $CI =& get_instance(); + $stock_tree = $this->add_sub_groups($start_id); + return $stock_tree; + } + + function add_sub_groups($id) + { + $CI =& get_instance(); + /* Adding current group */ + if ($id == 0) + { + $stock_group[$id] = array( + 'id' => $id, + 'name' => '', + 'type' => 'R', + 'sub_stock_groups' => array(), + 'sub_stock_items' => array(), + ); + } else { + $CI->db->from('stock_groups')->where('id', $id)->limit(1); + $current_stock_group_q = $CI->db->get(); + if ($current_stock_group = $current_stock_group_q->row()) + { + $stock_group[$id] = array( + 'id' => $id, + 'name' => $current_stock_group->name, + 'type' => 'G', + 'sub_stock_groups' => array(), + 'sub_stock_items' => array(), + ); + } + } + + /* Adding sub groups */ + $CI->db->from('stock_groups')->where('parent_id', $id)->order_by('name', 'asc'); + $stock_group_q = $CI->db->get(); + foreach ($stock_group_q->result() as $row) + { + $stock_group[$id]['sub_stock_groups'][$row->id] = $this->add_sub_groups($row->id); + } + + /* Adding sub item */ + $stock_group[$id]['sub_stock_items'] = $this->add_sub_item($id); + + return $stock_group; + } + + function add_sub_item($id) + { + $CI =& get_instance(); + $stock_items = array(); + $CI->db->from('stock_items')->where('stock_group_id', $id)->order_by('name', 'asc'); + $stock_item_q = $CI->db->get(); + foreach ($stock_item_q->result() as $row) + { + $stock_items[$row->id] = array( + 'id' => $row->id, + 'name' => $row->name, + 'type' => 'I', + 'costing_method' => $row->costing_method, + 'op_balance_quantity' => $row->op_balance_quantity, + 'op_balance_rate_per_unit' => $row->op_balance_rate_per_unit, + 'op_balance_total_value' => $row->op_balance_total_value, + ); + } + return $stock_items; + } + + /* + * Prints the entire stock tree as required in stock account list + */ + function print_tree($stock_tree) + { + self::$counter++; + foreach ($stock_tree as $row) + { + if ($row['id'] != 0) + { + echo "<tr class="tr-group">"; + echo "<td>" . self::print_spaces(self::$counter) . $row['name'] . "</td>"; + echo "<td>Stock Group</td>"; + echo "<td>-</td>"; + echo "<td>-</td>"; + echo "<td class="td-actions">" . anchor('inventory/stockgroup/edit/' . $row['id'] , "Edit", array('title' => 'Edit Stock Group', 'class' => 'red-link')); + echo " " . anchor('inventory/stockgroup/delete/' . $row['id'], img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Delete Stock Group')), array('class' => "confirmClick", 'title' => "Delete Stock Group")) . "</td>"; + echo "</tr>"; + } + if ($row['sub_stock_items']) + { + self::$counter++; + foreach ($row['sub_stock_items'] as $row_item) + { + echo "<tr>"; + echo "<td>" . self::print_spaces(self::$counter) . $row_item['name'] . "</td>"; + echo "<td>Stock Item</td>"; + echo "<td>" . convert_amount_dc($row_item['op_balance_total_value']) . "</td>"; + echo "<td></td>"; + echo "<td class="td-actions">" . anchor('inventory/stockitem/edit/' . $row_item['id'] , "Edit", array('title' => 'Edit Stock Item', 'class' => 'red-link')); + echo " " . anchor('inventory/stockitem/delete/' . $row_item['id'], img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Delete Stock Item')), array('class' => "confirmClick", 'title' => "Delete Stock Item")) . "</td>"; + echo "</tr>"; + } + self::$counter--; + } + if ($row['sub_stock_groups']) + { + foreach ($row['sub_stock_groups'] as $row_item) + { + self::print_tree($row_item); + } + } + } + self::$counter--; + } + + /* + * Prints empty spaces + */ + function print_spaces($counter) + { + $return_html = ''; + for ($c = 2; $c < $counter; $c++) + $return_html .= " "; + return $return_html; + } +} + diff --git a/system/application/views/inventory/account/index.php b/system/application/views/inventory/account/index.php index 107a44c..a961821 100644 --- a/system/application/views/inventory/account/index.php +++ b/system/application/views/inventory/account/index.php @@ -1,14 +1,5 @@ <?php - echo "<table>"; - echo "<tr valign="top">"; - echo "<td>"; - echo "<table border=0 cellpadding=5 class="simple-table account-table">"; - echo "<thead><tr><th>Account Name</th><th>Type</th><th>O/P Balance</th><th>C/L Balance</th><th></th></tr></thead>"; - echo "</table>"; - echo "</td>"; - echo "</tr>"; - echo "</table>"; - + /**************************** Stock Units *****************************/ echo "<table border=0 cellpadding=5 class="simple-table float-right">"; echo "<thead><tr><th>Stock Unit</th><th>Symbol</th><th></th></tr></thead>"; foreach ($stock_units->result() as $row) @@ -24,3 +15,14 @@ } echo "</table>";
+ /******************************* Stock Tree ***************************/ + echo "<table>"; + echo "<tr valign="top">"; + echo "<td>"; + echo "<table border=0 cellpadding=5 class="simple-table account-table">"; + echo "<thead><tr><th>Name</th><th>Type</th><th>O/P Balance</th><th>C/L Balance</th><th></th></tr></thead>"; + Stockstree::print_tree($stocks_tree); + echo "</table>"; + echo "</td>"; + echo "</tr>"; + echo "</table>";
commit ca54b66065450516410d69ab959589046c7c2235 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Sat Feb 5 13:45:48 2011 +0530
Added Stock Item actions
- Updated database schema for stock items - Added add/edit/delete actions - Added validation for quantity
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/db-update.txt b/db-update.txt index c358019..83856c3 100644 --- a/db-update.txt +++ b/db-update.txt @@ -8,6 +8,25 @@ CREATE TABLE IF NOT EXISTS stock_units ( PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
+CREATE TABLE IF NOT EXISTS stock_groups ( + id int(11) NOT NULL AUTO_INCREMENT, + parent_id varchar(11) NOT NULL, + name varchar(100) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; + +CREATE TABLE IF NOT EXISTS stock_items ( + id int(11) NOT NULL AUTO_INCREMENT, + stock_group_id int(11) NOT NULL, + stock_unit_id int(11) NOT NULL, + name varchar(100) NOT NULL, + costing_method int(2) NOT NULL, + op_balance_quantity float NOT NULL, + op_balance_rate_per_unit decimal(15,2) NOT NULL, + op_balance_total_value decimal(15,2) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; + //--------------------------------- VERSION 3 ----------------------------------
CREATE TABLE IF NOT EXISTS voucher_types ( diff --git a/system/application/controllers/admin/schema.sql b/system/application/controllers/admin/schema.sql index 5abac50..c2f3461 100644 --- a/system/application/controllers/admin/schema.sql +++ b/system/application/controllers/admin/schema.sql @@ -116,3 +116,16 @@ CREATE TABLE IF NOT EXISTS stock_groups ( name varchar(100) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; + +CREATE TABLE IF NOT EXISTS stock_items ( + id int(11) NOT NULL AUTO_INCREMENT, + stock_group_id int(11) NOT NULL, + stock_unit_id int(11) NOT NULL, + name varchar(100) NOT NULL, + costing_method int(2) NOT NULL, + op_balance_quantity float NOT NULL, + op_balance_rate_per_unit decimal(15,2) NOT NULL, + op_balance_total_value decimal(15,2) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; + diff --git a/system/application/controllers/inventory/stockitem.php b/system/application/controllers/inventory/stockitem.php new file mode 100644 index 0000000..e8fcdd0 --- /dev/null +++ b/system/application/controllers/inventory/stockitem.php @@ -0,0 +1,392 @@ +<?php + +class StockItem extends Controller { + + function StockItem() + { + parent::Controller(); + $this->load->model('Stock_Unit_model'); + $this->load->model('Stock_Group_model'); + $this->load->model('Stock_Item_model'); + return; + } + + function index() + { + redirect('inventory/stockitem/add'); + return; + } + + function add() + { + $this->template->set('page_title', 'New Stock Item'); + + /* Check access */ + if ( ! check_access('create stock item')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/account'); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('account'); + return; + } + + /* Form fields */ + $data['stock_item_name'] = array( + 'name' => 'stock_item_name', + 'id' => 'stock_item_name', + 'maxlength' => '100', + 'size' => '40', + 'value' => '', + ); + $data['stock_item_op_quantity'] = array( + 'name' => 'stock_item_op_quantity', + 'id' => 'stock_item_op_quantity', + 'maxlength' => '100', + 'size' => '40', + 'value' => '', + ); + $data['stock_item_op_rate_per_unit'] = array( + 'name' => 'stock_item_op_rate_per_unit', + 'id' => 'stock_item_op_rate_per_unit', + 'maxlength' => '100', + 'size' => '40', + 'value' => '', + ); + $data['stock_item_op_total'] = array( + 'name' => 'stock_item_op_total', + 'id' => 'stock_item_op_total', + 'maxlength' => '100', + 'size' => '40', + 'value' => '', + ); + $data['stock_item_costing_methods'] = array( + '1' => 'Last In First Out (LIFO)', + '2' => 'First In First Out (FIFO)', + ); + $data['stock_item_costing_method_active'] = 1; + $data['stock_item_units'] = $this->Stock_Unit_model->get_all_units(); + $data['stock_item_unit_active'] = 0; + $data['stock_item_groups'] = $this->Stock_Group_model->get_stock_item_groups(); + $data['stock_item_group_active'] = 0; + + /* Form validations */ + $this->form_validation->set_rules('stock_item_name', 'Stock item name', 'trim|required|min_length[2]|max_length[100]|unique[stock_items.name]'); + $this->form_validation->set_rules('stock_item_group', 'Stock group', 'trim|required|is_natural'); + $this->form_validation->set_rules('stock_item_unit', 'Stock unit', 'trim|required|is_natural'); + $this->form_validation->set_rules('stock_item_costing_method', 'Costing method', 'trim|required|is_natural'); + $this->form_validation->set_rules('stock_item_op_quantity', 'Opening Balance Quantity', 'trim|quantity'); + $this->form_validation->set_rules('stock_item_op_rate_per_unit', 'Opening Balance Rate per unit', 'trim|currency'); + $this->form_validation->set_rules('stock_item_op_total', 'Opening Balance Total value', 'trim|currency'); + + /* Re-populating form */ + if ($_POST) + { + $data['stock_item_name']['value'] = $this->input->post('stock_item_name', TRUE); + $data['stock_item_group_active'] = $this->input->post('stock_item_group', TRUE); + $data['stock_item_unit_active'] = $this->input->post('stock_item_unit', TRUE); + $data['stock_item_costing_method_active'] = $this->input->post('stock_item_costing_method', TRUE); + $data['stock_item_op_quantity']['value'] = $this->input->post('stock_item_op_quantity', TRUE); + $data['stock_item_op_rate_per_unit']['value'] = $this->input->post('stock_item_op_rate_per_unit', TRUE); + $data['stock_item_op_total']['value'] = $this->input->post('stock_item_op_total', TRUE); + } + + if ($this->form_validation->run() == FALSE) + { + $this->messages->add(validation_errors(), 'error'); + $this->template->load('template', 'inventory/stockitem/add', $data); + return; + } + else + { + $data_stock_item_name = $this->input->post('stock_item_name', TRUE); + $data_stock_item_group_id = $this->input->post('stock_item_group', TRUE); + $data_stock_item_unit_id = $this->input->post('stock_item_unit', TRUE); + $data_stock_item_costing_method = $this->input->post('stock_item_costing_method', TRUE); + $data_stock_item_op_quantity = $this->input->post('stock_item_op_quantity', TRUE); + $data_stock_item_op_rate_per_unit = $this->input->post('stock_item_op_rate_per_unit', TRUE); + $data_stock_item_op_total = $this->input->post('stock_item_op_total', TRUE); + + /* Check if stock group present */ + $this->db->select('id')->from('stock_groups')->where('id', $data_stock_item_group_id); + if ($this->db->get()->num_rows() < 1) + { + $this->messages->add('Invalid stock group.', 'error'); + $this->template->load('template', 'inventory/stockitem/add', $data); + return; + } + + /* Check if stock unit present */ + $this->db->select('id')->from('stock_units')->where('id', $data_stock_item_unit_id); + if ($this->db->get()->num_rows() < 1) + { + $this->messages->add('Invalid stock unit.', 'error'); + $this->template->load('template', 'inventory/stockitem/add', $data); + return; + } + + if (($data_stock_item_costing_method < 1) or ($data_stock_item_costing_method > 2)) + $data_stock_item_costing_method = 1; + + $this->db->trans_start(); + $insert_data = array( + 'name' => $data_stock_item_name, + 'stock_group_id' => $data_stock_item_group_id, + 'stock_unit_id' => $data_stock_item_unit_id, + 'costing_method' => $data_stock_item_costing_method, + 'op_balance_quantity' => $data_stock_item_op_quantity, + 'op_balance_rate_per_unit' => $data_stock_item_op_rate_per_unit, + 'op_balance_total_value' => $data_stock_item_op_total, + ); + if ( ! $this->db->insert('stock_items', $insert_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error addding Stock Item - ' . $data_stock_item_name . '.', 'error'); + $this->logger->write_message("error", "Error adding Stock Item named " . $data_stock_item_name); + $this->template->load('template', 'inventory/stockitem/add', $data); + return; + } else { + $this->db->trans_complete(); + $this->messages->add('Added Stock Item - ' . $data_stock_item_name . '.', 'success'); + $this->logger->write_message("success", "Added Stock Item named " . $data_stock_item_name); + redirect('inventory/account'); + return; + } + } + return; + } + + function edit($id) + { + $this->template->set('page_title', 'Edit Stock Item'); + + /* Check access */ + if ( ! check_access('edit stock item')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/account'); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('inventory/account'); + return; + } + + /* Checking for valid data */ + $id = $this->input->xss_clean($id); + $id = (int)$id; + if ($id < 1) { + $this->messages->add('Invalid Stock Item.', 'error'); + redirect('inventory/account'); + return; + } + + /* Loading current stock item */ + $this->db->from('stock_items')->where('id', $id); + $stock_item_data_q = $this->db->get(); + if ($stock_item_data_q->num_rows() < 1) + { + $this->messages->add('Invalid Stock Item.', 'error'); + redirect('inventory/account'); + return; + } + $stock_item_data = $stock_item_data_q->row(); + + /* Form fields */ + $data['stock_item_name'] = array( + 'name' => 'stock_item_name', + 'id' => 'stock_item_name', + 'maxlength' => '100', + 'size' => '40', + 'value' => $stock_item_data->name, + ); + $data['stock_item_op_quantity'] = array( + 'name' => 'stock_item_op_quantity', + 'id' => 'stock_item_op_quantity', + 'maxlength' => '100', + 'size' => '40', + 'value' => $stock_item_data->op_balance_quantity, + ); + $data['stock_item_op_rate_per_unit'] = array( + 'name' => 'stock_item_op_rate_per_unit', + 'id' => 'stock_item_op_rate_per_unit', + 'maxlength' => '100', + 'size' => '40', + 'value' => $stock_item_data->op_balance_rate_per_unit, + ); + $data['stock_item_op_total'] = array( + 'name' => 'stock_item_op_total', + 'id' => 'stock_item_op_total', + 'maxlength' => '100', + 'size' => '40', + 'value' => $stock_item_data->op_balance_total_value, + ); + $data['stock_item_costing_methods'] = array( + '1' => 'Last In First Out (LIFO)', + '2' => 'First In First Out (FIFO)', + ); + $data['stock_item_costing_method_active'] = $stock_item_data->costing_method; + $data['stock_item_units'] = $this->Stock_Unit_model->get_all_units(); + $data['stock_item_unit_active'] = $stock_item_data->stock_unit_id; + $data['stock_item_groups'] = $this->Stock_Group_model->get_stock_item_groups(); + $data['stock_item_group_active'] = $stock_item_data->stock_group_id; + $data['stock_item_id'] = $id; + + /* Form validations */ + $this->form_validation->set_rules('stock_item_name', 'Stock item name', 'trim|required|min_length[2]|max_length[100]|uniquewithid[stock_items.name.' . $id . ']'); + $this->form_validation->set_rules('stock_item_group', 'Stock group', 'trim|required|is_natural'); + $this->form_validation->set_rules('stock_item_unit', 'Stock unit', 'trim|required|is_natural'); + $this->form_validation->set_rules('stock_item_costing_method', 'Costing method', 'trim|required|is_natural'); + $this->form_validation->set_rules('stock_item_op_quantity', 'Opening Balance Quantity', 'trim|quantity'); + $this->form_validation->set_rules('stock_item_op_rate_per_unit', 'Opening Balance Rate per unit', 'trim|currency'); + $this->form_validation->set_rules('stock_item_op_total', 'Opening Balance Total value', 'trim|currency'); + + /* Re-populating form */ + if ($_POST) + { + $data['stock_item_name']['value'] = $this->input->post('stock_item_name', TRUE); + $data['stock_item_group_active'] = $this->input->post('stock_item_group', TRUE); + $data['stock_item_unit_active'] = $this->input->post('stock_item_unit', TRUE); + $data['stock_item_costing_method_active'] = $this->input->post('stock_item_costing_method', TRUE); + $data['stock_item_op_quantity']['value'] = $this->input->post('stock_item_op_quantity', TRUE); + $data['stock_item_op_rate_per_unit']['value'] = $this->input->post('stock_item_op_rate_per_unit', TRUE); + $data['stock_item_op_total']['value'] = $this->input->post('stock_item_op_total', TRUE); + } + + if ($this->form_validation->run() == FALSE) + { + $this->messages->add(validation_errors(), 'error'); + $this->template->load('template', 'inventory/stockitem/edit', $data); + return; + } + else + { + $data_stock_item_name = $this->input->post('stock_item_name', TRUE); + $data_stock_item_group_id = $this->input->post('stock_item_group', TRUE); + $data_stock_item_unit_id = $this->input->post('stock_item_unit', TRUE); + $data_stock_item_costing_method = $this->input->post('stock_item_costing_method', TRUE); + $data_stock_item_op_quantity = $this->input->post('stock_item_op_quantity', TRUE); + $data_stock_item_op_rate_per_unit = $this->input->post('stock_item_op_rate_per_unit', TRUE); + $data_stock_item_op_total = $this->input->post('stock_item_op_total', TRUE); + $data_id = $id; + + /* Check if stock group present */ + $this->db->select('id')->from('stock_groups')->where('id', $data_stock_item_group_id); + if ($this->db->get()->num_rows() < 1) + { + $this->messages->add('Invalid stock group.', 'error'); + $this->template->load('template', 'inventory/stockitem/add', $data); + return; + } + + /* Check if stock unit present */ + $this->db->select('id')->from('stock_units')->where('id', $data_stock_item_unit_id); + if ($this->db->get()->num_rows() < 1) + { + $this->messages->add('Invalid stock unit.', 'error'); + $this->template->load('template', 'inventory/stockitem/add', $data); + return; + } + + if (($data_stock_item_costing_method < 1) or ($data_stock_item_costing_method > 2)) + $data_stock_item_costing_method = 1; + + $this->db->trans_start(); + $update_data = array( + 'name' => $data_stock_item_name, + 'stock_group_id' => $data_stock_item_group_id, + 'stock_unit_id' => $data_stock_item_unit_id, + 'costing_method' => $data_stock_item_costing_method, + 'op_balance_quantity' => $data_stock_item_op_quantity, + 'op_balance_rate_per_unit' => $data_stock_item_op_rate_per_unit, + 'op_balance_total_value' => $data_stock_item_op_total, + ); + if ( ! $this->db->where('id', $data_id)->update('stock_items', $update_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error updating Stock Item - ' . $data_stock_item_name . '.', 'error'); + $this->logger->write_message("error", "Error updating Stock Item named " . $data_stock_item_name . " [id:" . $data_id . "]"); + $this->template->load('template', 'inventory/stockgroup/edit', $data); + return; + } else { + $this->db->trans_complete(); + $this->messages->add('Updated Stock Item - ' . $data_stock_item_name . '.', 'success'); + $this->logger->write_message("success", "Updated Stock Item named " . $data_stock_item_name . " [id:" . $data_id . "]"); + redirect('inventory/account'); + return; + } + } + return; + } + + function delete($id) + { + /* Check access */ + if ( ! check_access('delete stock item')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/account'); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('inventory/account'); + return; + } + + /* Checking for valid data */ + $id = $this->input->xss_clean($id); + $id = (int)$id; + if ($id < 1) { + $this->messages->add('Invalid Stock Item.', 'error'); + redirect('inventory/account'); + return; + } + + /* Get the stock item details */ + $this->db->from('stock_items')->where('id', $id); + $stock_item_q = $this->db->get(); + if ($stock_item_q->num_rows() < 1) + { + $this->messages->add('Invalid Stock Item.', 'error'); + redirect('inventory/account'); + return; + } else { + $stock_item_data = $stock_item_q->row(); + } + + /* Deleting item */ + $this->db->trans_start(); + if ( ! $this->db->delete('stock_items', array('id' => $id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting Stock Item - ' . $stock_item_data->name . '.', 'error'); + $this->logger->write_message("error", "Error deleting Stock Item named " . $stock_item_data->name . " [id:" . $id . "]"); + redirect('inventory/account'); + return; + } else { + $this->db->trans_complete(); + $this->messages->add('Deleted Stock Item - ' . $stock_item_data->name . '.', 'success'); + $this->logger->write_message("success", "Deleted Stock Item named " . $stock_item_data->name . " [id:" . $id . "]"); + redirect('inventory/account'); + return; + } + return; + } +} + +/* End of file stockitem.php */ +/* Location: ./system/application/controllers/inventory/stockitem.php */ diff --git a/system/application/controllers/inventory/stockunit.php b/system/application/controllers/inventory/stockunit.php index 29922db..0e1a503 100644 --- a/system/application/controllers/inventory/stockunit.php +++ b/system/application/controllers/inventory/stockunit.php @@ -247,6 +247,15 @@ class StockUnit extends Controller { return; }
+ /* Checking if linked to any stock item */ + $this->db->from('stock_items')->where('stock_unit_id', $id); + if ($this->db->get()->num_rows() > 0) + { + $this->messages->add('Cannot delete Stock Unit. Stock Unit is still in use.', 'error'); + redirect('inventory/account'); + return; + } + /* Get the stock unit details */ $this->db->from('stock_units')->where('id', $id); $stock_unit_q = $this->db->get(); diff --git a/system/application/libraries/MY_Form_validation.php b/system/application/libraries/MY_Form_validation.php index 06624e3..a795821 100644 --- a/system/application/libraries/MY_Form_validation.php +++ b/system/application/libraries/MY_Form_validation.php @@ -100,6 +100,24 @@ class MY_Form_validation extends CI_Form_validation { } }
+ function quantity($str) + { + $CI =& get_instance(); + if (preg_match('/^[-]/', $str)) + { + $CI->form_validation->set_message('quantity', '%s cannot be negative.'); + return FALSE; + } + + if (preg_match('/^[0-9]*.?[0-9]{0,4}$/', $str)) + { + return TRUE; + } else { + $CI->form_validation->set_message('quantity', '%s must be a valid quantity. Maximum 4 decimal places are allowed.'); + return FALSE; + } + } + function is_date($str) { $CI =& get_instance(); diff --git a/system/application/models/stock_group_model.php b/system/application/models/stock_group_model.php index 0388121..47b6bff 100644 --- a/system/application/models/stock_group_model.php +++ b/system/application/models/stock_group_model.php @@ -22,4 +22,16 @@ class Stock_Group_model extends Model { } return $options; } + + function get_stock_item_groups() + { + $options = array(); + $this->db->from('stock_groups')->where('id >', 0)->order_by('name', 'asc'); + $stock_item_parent_q = $this->db->get(); + foreach ($stock_item_parent_q->result() as $row) + { + $options[$row->id] = $row->name; + } + return $options; + } } diff --git a/system/application/models/stock_item_model.php b/system/application/models/stock_item_model.php new file mode 100644 index 0000000..da33e9f --- /dev/null +++ b/system/application/models/stock_item_model.php @@ -0,0 +1,32 @@ +<?php + +class Stock_Item_model extends Model { + + function Stock_Item_model() + { + parent::Model(); + } + + function get_all_item() + { + $options = array(); + $options[0] = "(Please Select)"; + $this->db->from('stock_items')->order_by('name', 'asc'); + $ledger_q = $this->db->get(); + foreach ($ledger_q->result() as $row) + { + $options[$row->id] = $row->name; + } + return $options; + } + + function get_name($stock_item_id) + { + $this->db->from('stock_items')->where('id', $stock_item_id)->limit(1); + $stock_item_q = $this->db->get(); + if ($stock_item = $stock_item_q->row()) + return $stock_item->name; + else + return "(Error)"; + } +} diff --git a/system/application/models/stock_unit_model.php b/system/application/models/stock_unit_model.php new file mode 100644 index 0000000..2521b95 --- /dev/null +++ b/system/application/models/stock_unit_model.php @@ -0,0 +1,21 @@ +<?php + +class Stock_Unit_model extends Model { + + function Stock_Unit_model() + { + parent::Model(); + } + + function get_all_units() + { + $options = array(); + $this->db->from('stock_units')->where('id >', 0)->order_by('symbol', 'asc'); + $stock_unit_q = $this->db->get(); + foreach ($stock_unit_q->result() as $row) + { + $options[$row->id] = $row->symbol; + } + return $options; + } +} diff --git a/system/application/views/inventory/stockgroup/add.php b/system/application/views/inventory/stockgroup/add.php index 623f4b4..9d40a9e 100644 --- a/system/application/views/inventory/stockgroup/add.php +++ b/system/application/views/inventory/stockgroup/add.php @@ -16,7 +16,7 @@ echo "<p>"; echo form_submit('submit', 'Create'); echo " "; - echo anchor('inventory/account', 'Back', 'Back to Inventory'); + echo anchor('inventory/account', 'Back', array('title' => 'Back to Inventory')); echo "</p>";
echo form_close(); diff --git a/system/application/views/inventory/stockgroup/edit.php b/system/application/views/inventory/stockgroup/edit.php index b41b7f0..636df09 100644 --- a/system/application/views/inventory/stockgroup/edit.php +++ b/system/application/views/inventory/stockgroup/edit.php @@ -16,7 +16,7 @@ echo "<p>"; echo form_submit('submit', 'Update'); echo " "; - echo anchor('inventory/account', 'Back', 'Back to Inventory'); + echo anchor('inventory/account', 'Back', array('title' => 'Back to Inventory')); echo "</p>";
echo form_close(); diff --git a/system/application/views/inventory/stockitem/add.php b/system/application/views/inventory/stockitem/add.php new file mode 100644 index 0000000..e9e8652 --- /dev/null +++ b/system/application/views/inventory/stockitem/add.php @@ -0,0 +1,58 @@ +<?php + echo form_open('inventory/stockitem/add'); + + echo "<p>"; + echo form_label('Stock item name', 'stock_item_name'); + echo "<br />"; + echo form_input($stock_item_name); + echo "</p>"; + + echo "<p>"; + echo form_label('Stock group', 'stock_item_group'); + echo "<br />"; + echo form_dropdown('stock_item_group', $stock_item_groups, $stock_item_group_active); + echo "</p>"; + + echo "<p>"; + echo form_label('Stock unit', 'stock_item_unit'); + echo "<br />"; + echo form_dropdown('stock_item_unit', $stock_item_units, $stock_item_unit_active); + echo "</p>"; + + echo "<p>"; + echo form_label('Costing method', 'stock_item_costing_method'); + echo "<br />"; + echo form_dropdown('stock_item_costing_method', $stock_item_costing_methods, $stock_item_costing_method_active); + echo "</p>"; + + echo "<p>"; + echo form_fieldset('Opening Balance', array('class' => "fieldset-auto-width")); + + echo "<p>"; + echo form_label('Quantity', 'stock_item_op_quantity'); + echo "<br />"; + echo form_input($stock_item_op_quantity); + echo "</p>"; + + echo "<p>"; + echo form_label('Rate per unit', 'stock_item_op_rate_per_unit'); + echo "<br />"; + echo form_input($stock_item_op_rate_per_unit); + echo "</p>"; + + echo "<p>"; + echo form_label('Total value', 'stock_item_op_total'); + echo "<br />"; + echo form_input($stock_item_op_total); + echo "</p>"; + + echo form_fieldset_close(); + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Create'); + echo " "; + echo anchor('inventory/account', 'Back', array('title' => 'Back to Inventory')); + echo "</p>"; + + echo form_close(); diff --git a/system/application/views/inventory/stockitem/edit.php b/system/application/views/inventory/stockitem/edit.php new file mode 100644 index 0000000..f5fd1be --- /dev/null +++ b/system/application/views/inventory/stockitem/edit.php @@ -0,0 +1,58 @@ +<?php + echo form_open('inventory/stockitem/edit/' . $stock_item_id); + + echo "<p>"; + echo form_label('Stock item name', 'stock_item_name'); + echo "<br />"; + echo form_input($stock_item_name); + echo "</p>"; + + echo "<p>"; + echo form_label('Stock group', 'stock_item_group'); + echo "<br />"; + echo form_dropdown('stock_item_group', $stock_item_groups, $stock_item_group_active); + echo "</p>"; + + echo "<p>"; + echo form_label('Stock unit', 'stock_item_unit'); + echo "<br />"; + echo form_dropdown('stock_item_unit', $stock_item_units, $stock_item_unit_active); + echo "</p>"; + + echo "<p>"; + echo form_label('Costing method', 'stock_item_costing_method'); + echo "<br />"; + echo form_dropdown('stock_item_costing_method', $stock_item_costing_methods, $stock_item_costing_method_active); + echo "</p>"; + + echo "<p>"; + echo form_fieldset('Opening Balance', array('class' => "fieldset-auto-width")); + + echo "<p>"; + echo form_label('Quantity', 'stock_item_op_quantity'); + echo "<br />"; + echo form_input($stock_item_op_quantity); + echo "</p>"; + + echo "<p>"; + echo form_label('Rate per unit', 'stock_item_op_rate_per_unit'); + echo "<br />"; + echo form_input($stock_item_op_rate_per_unit); + echo "</p>"; + + echo "<p>"; + echo form_label('Total value', 'stock_item_op_total'); + echo "<br />"; + echo form_input($stock_item_op_total); + echo "</p>"; + + echo form_fieldset_close(); + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Update'); + echo " "; + echo anchor('inventory/account', 'Back', array('title' => 'Back to Inventory')); + echo "</p>"; + + echo form_close(); diff --git a/system/application/views/inventory/stockunit/add.php b/system/application/views/inventory/stockunit/add.php index 4ecd28c..9a4ac65 100644 --- a/system/application/views/inventory/stockunit/add.php +++ b/system/application/views/inventory/stockunit/add.php @@ -25,7 +25,7 @@ echo "<p>"; echo form_submit('submit', 'Create'); echo " "; - echo anchor('inventory/account', 'Back', 'Back to Inventory'); + echo anchor('inventory/account', 'Back', array('title' => 'Back to Inventory')); echo "</p>";
echo form_close(); diff --git a/system/application/views/inventory/stockunit/edit.php b/system/application/views/inventory/stockunit/edit.php index 12930e5..131b851 100644 --- a/system/application/views/inventory/stockunit/edit.php +++ b/system/application/views/inventory/stockunit/edit.php @@ -25,7 +25,7 @@ echo "<p>"; echo form_submit('submit', 'Udpate'); echo " "; - echo anchor('inventory/account', 'Back', 'Back to Inventory'); + echo anchor('inventory/account', 'Back', array('title' => 'Back to Inventory')); echo "</p>";
echo form_close();
commit 66e1a211bafd064d71efb7de06087c45b8254e66 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Fri Feb 4 21:52:58 2011 +0530
Added Stock Group to database schema
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/admin/schema.sql b/system/application/controllers/admin/schema.sql index b54c129..5abac50 100644 --- a/system/application/controllers/admin/schema.sql +++ b/system/application/controllers/admin/schema.sql @@ -110,3 +110,9 @@ CREATE TABLE IF NOT EXISTS stock_units ( PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
+CREATE TABLE IF NOT EXISTS stock_groups ( + id int(11) NOT NULL AUTO_INCREMENT, + parent_id varchar(11) NOT NULL, + name varchar(100) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
commit 984d827e3ca23c732d319d2d4587a3702efcabc0 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Fri Feb 4 21:30:54 2011 +0530
Added Stock Group actions
- Added permissions - Added add/edit/delete stock group actions
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/inventory/stockgroup.php b/system/application/controllers/inventory/stockgroup.php new file mode 100644 index 0000000..0ec19c9 --- /dev/null +++ b/system/application/controllers/inventory/stockgroup.php @@ -0,0 +1,302 @@ +<?php + +class StockGroup extends Controller { + + function StockGroup() + { + parent::Controller(); + $this->load->model('Stock_Group_model'); + return; + } + + function index() + { + redirect('inventory/stockgroup/add'); + return; + } + + function add() + { + $this->template->set('page_title', 'New Stock Group'); + + /* Check access */ + if ( ! check_access('create stock group')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/account'); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('account'); + return; + } + + /* Form fields */ + $data['stock_group_name'] = array( + 'name' => 'stock_group_name', + 'id' => 'stock_group_name', + 'maxlength' => '100', + 'size' => '40', + 'value' => '', + ); + $data['stock_group_parents'] = $this->Stock_Group_model->get_all_stock_groups(); + $data['stock_group_parent_active'] = 0; + + /* Form validations */ + $this->form_validation->set_rules('stock_group_name', 'Stock group name', 'trim|required|min_length[2]|max_length[100]|unique[stock_groups.name]'); + $this->form_validation->set_rules('stock_group_parent', 'Parent stock group', 'trim|required|is_natural'); + + /* Re-populating form */ + if ($_POST) + { + $data['stock_group_name']['value'] = $this->input->post('stock_group_name', TRUE); + $data['stock_group_parent_active'] = $this->input->post('stock_group_parent', TRUE); + } + + if ($this->form_validation->run() == FALSE) + { + $this->messages->add(validation_errors(), 'error'); + $this->template->load('template', 'inventory/stockgroup/add', $data); + return; + } + else + { + $data_stock_group_name = $this->input->post('stock_group_name', TRUE); + $data_stock_group_parent_id = $this->input->post('stock_group_parent', TRUE); + + /* Check if parent group id present */ + if ($data_stock_group_parent_id > 0) + { + $this->db->select('id')->from('stock_groups')->where('id', $data_stock_group_parent_id); + if ($this->db->get()->num_rows() < 1) + { + $this->messages->add('Invalid parent stock group.', 'error'); + $this->template->load('template', 'inventory/stockgroup/add', $data); + return; + } + } + + $this->db->trans_start(); + $insert_data = array( + 'name' => $data_stock_group_name, + 'parent_id' => $data_stock_group_parent_id, + ); + if ( ! $this->db->insert('stock_groups', $insert_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error addding Stock Group - ' . $data_stock_group_name . '.', 'error'); + $this->logger->write_message("error", "Error adding Stock Group named " . $data_stock_group_name); + $this->template->load('template', 'inventory/stockgroup/add', $data); + return; + } else { + $this->db->trans_complete(); + $this->messages->add('Added Stock Group - ' . $data_stock_group_name . '.', 'success'); + $this->logger->write_message("success", "Added Stock Group named " . $data_stock_group_name); + redirect('inventory/account'); + return; + } + } + return; + } + + function edit($id) + { + $this->template->set('page_title', 'Edit Stock Group'); + + /* Check access */ + if ( ! check_access('edit stock group')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/account'); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('inventory/account'); + return; + } + + /* Checking for valid data */ + $id = $this->input->xss_clean($id); + $id = (int)$id; + if ($id < 1) { + $this->messages->add('Invalid Stock Group.', 'error'); + redirect('inventory/account'); + return; + } + + /* Loading current group */ + $this->db->from('stock_groups')->where('id', $id); + $stock_group_data_q = $this->db->get(); + if ($stock_group_data_q->num_rows() < 1) + { + $this->messages->add('Invalid Stock Group.', 'error'); + redirect('inventory/account'); + return; + } + $stock_group_data = $stock_group_data_q->row(); + + /* Form fields */ + $data['stock_group_name'] = array( + 'name' => 'stock_group_name', + 'id' => 'stock_group_name', + 'maxlength' => '100', + 'size' => '40', + 'value' => $stock_group_data->name, + ); + $data['stock_group_parents'] = $this->Stock_Group_model->get_all_stock_groups($stock_group_data->id); + $data['stock_group_parent_active'] = $stock_group_data->parent_id; + $data['stock_group_id'] = $id; + + /* Form validations */ + $this->form_validation->set_rules('stock_group_name', 'Stock group name', 'trim|required|min_length[2]|max_length[100]|uniquewithid[stock_groups.name.' . $id . ']'); + $this->form_validation->set_rules('stock_group_parent', 'Parent stock group', 'trim|required|is_natural'); + + /* Re-populating form */ + if ($_POST) + { + $data['stock_group_name']['value'] = $this->input->post('stock_group_name', TRUE); + $data['stock_group_parent_active'] = $this->input->post('stock_group_parent', TRUE); + } + + if ($this->form_validation->run() == FALSE) + { + $this->messages->add(validation_errors(), 'error'); + $this->template->load('template', 'inventory/stockgroup/edit', $data); + return; + } + else + { + $data_stock_group_name = $this->input->post('stock_group_name', TRUE); + $data_stock_group_parent_id = $this->input->post('stock_group_parent', TRUE); + $data_id = $id; + + /* Check if parent group id present */ + if ($data_stock_group_parent_id > 0) + { + $this->db->select('id')->from('stock_groups')->where('id', $data_stock_group_parent_id); + if ($this->db->get()->num_rows() < 1) + { + $this->messages->add('Invalid parent stock group.', 'error'); + $this->template->load('template', 'inventory/stockgroup/edit', $data); + return; + } + } + + /* Check if parent group same as current group id */ + if ($data_stock_group_parent_id > 0) + { + if ($data_stock_group_parent_id == $id) + { + $this->messages->add('Invalid Parent stock group', 'error'); + $this->template->load('template', 'inventory/stockgroup/edit', $data); + return; + } + } + + $this->db->trans_start(); + $update_data = array( + 'name' => $data_stock_group_name, + 'parent_id' => $data_stock_group_parent_id, + ); + if ( ! $this->db->where('id', $data_id)->update('stock_groups', $update_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error updating Stock Group - ' . $data_stock_group_name . '.', 'error'); + $this->logger->write_message("error", "Error updating Stock Group named " . $data_stock_group_name . " [id:" . $data_id . "]"); + $this->template->load('template', 'inventory/stockgroup/edit', $data); + return; + } else { + $this->db->trans_complete(); + $this->messages->add('Updated Stock Group - ' . $data_stock_group_name . '.', 'success'); + $this->logger->write_message("success", "Updated Stock Group named " . $data_stock_group_name . " [id:" . $data_id . "]"); + redirect('inventory/account'); + return; + } + } + return; + } + + function delete($id) + { + /* Check access */ + if ( ! check_access('delete stock group')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/account'); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('inventory/account'); + return; + } + + /* Checking for valid data */ + $id = $this->input->xss_clean($id); + $id = (int)$id; + if ($id < 1) { + $this->messages->add('Invalid Stock Group.', 'error'); + redirect('inventory/account'); + return; + } + + $this->db->from('stock_groups')->where('parent_id', $id); + if ($this->db->get()->num_rows() > 0) + { + $this->messages->add('Cannot delete non-empty Stock Group.', 'error'); + redirect('inventory/account'); + return; + } + $this->db->from('stock_items')->where('group_id', $id); + if ($this->db->get()->num_rows() > 0) + { + $this->messages->add('Cannot delete non-empty Stock Group.', 'error'); + redirect('inventory/account'); + return; + } + + /* Get the group details */ + $this->db->from('stock_groups')->where('id', $id); + $stock_group_q = $this->db->get(); + if ($stock_group_q->num_rows() < 1) + { + $this->messages->add('Invalid Stock Group.', 'error'); + redirect('inventory/account'); + return; + } else { + $stock_group_data = $stock_group_q->row(); + } + + /* Deleting group */ + $this->db->trans_start(); + if ( ! $this->db->delete('stock_groups', array('id' => $id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting Stock Group - ' . $stock_group_data->name . '.', 'error'); + $this->logger->write_message("error", "Error deleting Stock Group named " . $stock_group_data->name . " [id:" . $id . "]"); + redirect('inventory/account'); + return; + } else { + $this->db->trans_complete(); + $this->messages->add('Deleted Stock Group - ' . $stock_group_data->name . '.', 'success'); + $this->logger->write_message("success", "Deleted Stock Group named " . $stock_group_data->name . " [id:" . $id . "]"); + redirect('inventory/account'); + return; + } + return; + } +} + +/* End of file stockgroup.php */ +/* Location: ./system/application/controllers/inventory/stockgroup.php */ diff --git a/system/application/helpers/access_helper.php b/system/application/helpers/access_helper.php index 86c939d..35e7067 100644 --- a/system/application/helpers/access_helper.php +++ b/system/application/helpers/access_helper.php @@ -22,6 +22,9 @@ * 'create stock unit' * 'edit stock unit' * 'delete stock unit' + * 'create stock group' + * 'edit stock group' + * 'delete stock group' * 'create tag' * 'edit tag' * 'delete tag' @@ -57,6 +60,9 @@ if ( ! function_exists('check_access')) 'create stock unit', 'edit stock unit', 'delete stock unit', + 'create stock group', + 'edit stock group', + 'delete stock group', 'create tag', 'edit tag', 'delete tag', @@ -84,6 +90,9 @@ if ( ! function_exists('check_access')) 'create stock unit', 'edit stock unit', 'delete stock unit', + 'create stock group', + 'edit stock group', + 'delete stock group', 'create tag', 'edit tag', 'delete tag', diff --git a/system/application/models/stock_group_model.php b/system/application/models/stock_group_model.php new file mode 100644 index 0000000..0388121 --- /dev/null +++ b/system/application/models/stock_group_model.php @@ -0,0 +1,25 @@ +<?php + +class Stock_Group_model extends Model { + + function Stock_Group_model() + { + parent::Model(); + } + + function get_all_stock_groups($id = NULL) + { + $options = array(); + $options[0] = '(None)'; + if ($id == NULL) + $this->db->from('stock_groups')->where('id >', 0)->order_by('name', 'asc'); + else + $this->db->from('stock_groups')->where('id >', 0)->where('id !=', $id)->order_by('name', 'asc'); + $stock_group_parent_q = $this->db->get(); + foreach ($stock_group_parent_q->result() as $row) + { + $options[$row->id] = $row->name; + } + return $options; + } +} diff --git a/system/application/views/inventory/stockgroup/add.php b/system/application/views/inventory/stockgroup/add.php new file mode 100644 index 0000000..623f4b4 --- /dev/null +++ b/system/application/views/inventory/stockgroup/add.php @@ -0,0 +1,22 @@ +<?php + echo form_open('inventory/stockgroup/add'); + + echo "<p>"; + echo form_label('Stock group name', 'stock_group_name'); + echo "<br />"; + echo form_input($stock_group_name); + echo "</p>"; + + echo "<p>"; + echo form_label('Parent stock group', 'stock_group_parent'); + echo "<br />"; + echo form_dropdown('stock_group_parent', $stock_group_parents, $stock_group_parent_active); + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Create'); + echo " "; + echo anchor('inventory/account', 'Back', 'Back to Inventory'); + echo "</p>"; + + echo form_close(); diff --git a/system/application/views/inventory/stockgroup/edit.php b/system/application/views/inventory/stockgroup/edit.php new file mode 100644 index 0000000..b41b7f0 --- /dev/null +++ b/system/application/views/inventory/stockgroup/edit.php @@ -0,0 +1,22 @@ +<?php + echo form_open('inventory/stockgroup/edit/' . $stock_group_id); + + echo "<p>"; + echo form_label('Stock group name', 'stock_group_name'); + echo "<br />"; + echo form_input($stock_group_name); + echo "</p>"; + + echo "<p>"; + echo form_label('Parent stock group', 'stock_group_parent'); + echo "<br />"; + echo form_dropdown('stock_group_parent', $stock_group_parents, $stock_group_parent_active); + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Update'); + echo " "; + echo anchor('inventory/account', 'Back', 'Back to Inventory'); + echo "</p>"; + + echo form_close();
commit c9f9fb8420f95529fba87a1b190916044919866f Author: Prashant P Shah pshah.mumbai@gmail.com Date: Fri Feb 4 16:56:03 2011 +0530
Updated database schema to version 4
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/db-update.txt b/db-update.txt index 6ab82ca..c358019 100644 --- a/db-update.txt +++ b/db-update.txt @@ -1,3 +1,13 @@ +//--------------------------------- VERSION 4 ---------------------------------- + +CREATE TABLE IF NOT EXISTS stock_units ( + id int(11) NOT NULL AUTO_INCREMENT, + symbol varchar(15) NOT NULL, + name varchar(100) NOT NULL, + decimal_places int(2) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; + //--------------------------------- VERSION 3 ----------------------------------
CREATE TABLE IF NOT EXISTS voucher_types ( diff --git a/system/application/controllers/admin/create.php b/system/application/controllers/admin/create.php index 28c8837..dba6d82 100644 --- a/system/application/controllers/admin/create.php +++ b/system/application/controllers/admin/create.php @@ -322,7 +322,7 @@ class Create extends Controller {
/* Adding account settings */ $newacc->trans_start(); - if ( ! $newacc->query("INSERT INTO settings (id, name, address, email, fy_start, fy_end, currency_symbol, date_format, timezone, account_locked, database_version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array(1, $data_account_name, $data_account_address, $data_account_email, $data_fy_start, $data_fy_end, $data_account_currency, $data_account_date, $data_account_timezone, 0, 3))) + if ( ! $newacc->query("INSERT INTO settings (id, name, address, email, fy_start, fy_end, currency_symbol, date_format, timezone, account_locked, database_version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array(1, $data_account_name, $data_account_address, $data_account_email, $data_fy_start, $data_fy_end, $data_account_currency, $data_account_date, $data_account_timezone, 0, 4))) { $newacc->trans_rollback(); $this->messages->add('Error adding account settings.', 'error'); diff --git a/system/application/controllers/setting/cf.php b/system/application/controllers/setting/cf.php index ce9c1f2..f821602 100644 --- a/system/application/controllers/setting/cf.php +++ b/system/application/controllers/setting/cf.php @@ -269,7 +269,7 @@ class Cf extends Controller {
/* Adding account settings */ $newacc->trans_start(); - if ( ! $newacc->query("INSERT INTO settings (id, name, address, email, fy_start, fy_end, currency_symbol, date_format, timezone, account_locked, email_protocol, email_host, email_port, email_username, email_password, database_version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array(1, $data_account_name, $data_account_address, $data_account_email, $data_fy_start, $data_fy_end, $data_account_currency, $data_account_date, $data_account_timezone, 0, $data_account_email_protocol, $data_account_email_host, $data_account_email_port, $data_account_email_username, $data_account_email_password, 3))) + if ( ! $newacc->query("INSERT INTO settings (id, name, address, email, fy_start, fy_end, currency_symbol, date_format, timezone, account_locked, email_protocol, email_host, email_port, email_username, email_password, database_version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array(1, $data_account_name, $data_account_address, $data_account_email, $data_fy_start, $data_fy_end, $data_account_currency, $data_account_date, $data_account_timezone, 0, $data_account_email_protocol, $data_account_email_host, $data_account_email_port, $data_account_email_username, $data_account_email_password, 4))) { $newacc->trans_rollback(); $this->messages->add('Error adding account settings.', 'error');
commit 8fc65110bc66fa39fe6ac9e295321a18892f0cc4 Author: Prashant P Shah pshah.mumbai@gmail.com Date: Fri Feb 4 16:52:21 2011 +0530
Added Stock Unit actions
- Updated database schema - Added add/edit/delete actions for Stock Units - Added menu item for Inventory
Signed-off-by: Prashant P Shah pshah.mumbai@gmail.com
diff --git a/system/application/controllers/admin/schema.sql b/system/application/controllers/admin/schema.sql index 2f8f010..b54c129 100644 --- a/system/application/controllers/admin/schema.sql +++ b/system/application/controllers/admin/schema.sql @@ -101,3 +101,12 @@ CREATE TABLE IF NOT EXISTS settings ( print_page_format varchar(1) NOT NULL, database_version int(10) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +CREATE TABLE IF NOT EXISTS stock_units ( + id int(11) NOT NULL AUTO_INCREMENT, + symbol varchar(15) NOT NULL, + name varchar(100) NOT NULL, + decimal_places int(2) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; + diff --git a/system/application/controllers/inventory/account.php b/system/application/controllers/inventory/account.php new file mode 100644 index 0000000..3201ef0 --- /dev/null +++ b/system/application/controllers/inventory/account.php @@ -0,0 +1,19 @@ +<?php + +class Account extends Controller { + function index() + { + $this->template->set('page_title', 'Inventory'); + $this->template->set('nav_links', array('inventory/stockgroup/add' => 'New Stock Group', 'inventory/stockitem/add' => 'New Stock Item', 'inventory/stockunit/add' => 'New Stock Unit')); + + /* Stock Units */ + $this->db->from('stock_units')->order_by('name', 'desc'); + $data['stock_units'] = $this->db->get(); + + $this->template->load('template', 'inventory/account/index', $data); + return; + } +} + +/* End of file account.php */ +/* Location: ./system/application/controllers/inventory/account.php */ diff --git a/system/application/controllers/inventory/stockunit.php b/system/application/controllers/inventory/stockunit.php new file mode 100644 index 0000000..29922db --- /dev/null +++ b/system/application/controllers/inventory/stockunit.php @@ -0,0 +1,283 @@ +<?php + +class StockUnit extends Controller { + + function StockUnit() + { + parent::Controller(); + return; + } + + function index() + { + redirect('inventory/stockunit/add'); + return; + } + + function add() + { + $this->template->set('page_title', 'New Stock Unit'); + + /* Check access */ + if ( ! check_access('create stock unit')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/account'); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('inventory/account'); + return; + } + + /* Form fields */ + $data['stock_unit_symbol'] = array( + 'name' => 'stock_unit_symbol', + 'id' => 'stock_unit_symbol', + 'maxlength' => '15', + 'size' => '15', + 'value' => '', + ); + $data['stock_unit_name'] = array( + 'name' => 'stock_unit_name', + 'id' => 'stock_unit_name', + 'maxlength' => '100', + 'size' => '40', + 'value' => '', + ); + $data['stock_unit_decimal'] = array( + 'name' => 'stock_unit_decimal', + 'id' => 'stock_unit_decimal', + 'maxlength' => '1', + 'size' => '1', + 'value' => '0', + ); + + /* Form validations */ + $this->form_validation->set_rules('stock_unit_symbol', 'Stock Unit Symbol', 'trim|required|min_length[2]|max_length[15]|unique[stock_units.symbol]'); + $this->form_validation->set_rules('stock_unit_name', 'Stock Unit Name', 'trim|required|min_length[2]|max_length[100]|unique[stock_units.name]'); + $this->form_validation->set_rules('stock_unit_decimal', 'Decimal Places', 'trim|required|max_length[1]|is_natural'); + + /* Re-populating form */ + if ($_POST) + { + $data['stock_unit_symbol']['value'] = $this->input->post('stock_unit_symbol', TRUE); + $data['stock_unit_name']['value'] = $this->input->post('stock_unit_name', TRUE); + $data['stock_unit_decimal']['value'] = $this->input->post('stock_unit_decimal', TRUE); + } + + if ($this->form_validation->run() == FALSE) + { + $this->messages->add(validation_errors(), 'error'); + $this->template->load('template', 'inventory/stockunit/add', $data); + return; + } + else + { + $data_stock_unit_symbol = $this->input->post('stock_unit_symbol', TRUE); + $data_stock_unit_name = $this->input->post('stock_unit_name', TRUE); + $data_stock_unit_decimal = $this->input->post('stock_unit_decimal', TRUE); + + $this->db->trans_start(); + $insert_data = array( + 'symbol' => $data_stock_unit_symbol, + 'name' => $data_stock_unit_name, + 'decimal_places' => $data_stock_unit_decimal, + ); + if ( ! $this->db->insert('stock_units', $insert_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error addding Stock Unit - ' . $data_stock_unit_name . '.', 'error'); + $this->logger->write_message("error", "Error adding Stock Unit named " . $data_stock_unit_name); + $this->template->load('template', 'inventory/stockunit/add', $data); + return; + } else { + $this->db->trans_complete(); + $this->messages->add('Added Stock Unit - ' . $data_stock_unit_name . '.', 'success'); + $this->logger->write_message("success", "Added Stock Unit named " . $data_stock_unit_name); + redirect('inventory/account'); + return; + } + } + return; + } + + function edit($id) + { + $this->template->set('page_title', 'Edit Stock Unit'); + + /* Check access */ + if ( ! check_access('edit stock unit')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/account'); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('inventory/account'); + return; + } + + /* Checking for valid data */ + $id = $this->input->xss_clean($id); + $id = (int)$id; + if ($id < 1) { + $this->messages->add('Invalid Stock Unit.', 'error'); + redirect('inventory/account'); + return; + } + + /* Loading current stock unit */ + $this->db->from('stock_units')->where('id', $id); + $stock_unit_data_q = $this->db->get(); + if ($stock_unit_data_q->num_rows() < 1) + { + $this->messages->add('Invalid Stock Unit.', 'error'); + redirect('inventory/account'); + return; + } + $stock_unit_data = $stock_unit_data_q->row(); + + /* Form fields */ + $data['stock_unit_symbol'] = array( + 'name' => 'stock_unit_symbol', + 'id' => 'stock_unit_symbol', + 'maxlength' => '15', + 'size' => '15', + 'value' => $stock_unit_data->symbol, + ); + $data['stock_unit_name'] = array( + 'name' => 'stock_unit_name', + 'id' => 'stock_unit_name', + 'maxlength' => '100', + 'size' => '40', + 'value' => $stock_unit_data->name, + ); + $data['stock_unit_decimal'] = array( + 'name' => 'stock_unit_decimal', + 'id' => 'stock_unit_decimal', + 'maxlength' => '1', + 'size' => '1', + 'value' => $stock_unit_data->decimal_places, + ); + $data['stock_unit_id'] = $id; + + /* Form validations */ + $this->form_validation->set_rules('stock_unit_symbol', 'Stock Unit Symbol', 'trim|required|min_length[2]|max_length[15]|uniquewithid[stock_units.symbol.' . $id . ']'); + $this->form_validation->set_rules('stock_unit_name', 'Stock Unit Name', 'trim|required|min_length[2]|max_length[100]|uniquewithid[stock_units.name.' . $id . ']'); + $this->form_validation->set_rules('stock_unit_decimal', 'Decimal Places', 'trim|required|max_length[1]|is_natural'); + + /* Re-populating form */ + if ($_POST) + { + $data['stock_unit_symbol']['value'] = $this->input->post('stock_unit_symbol', TRUE); + $data['stock_unit_name']['value'] = $this->input->post('stock_unit_name', TRUE); + $data['stock_unit_decimal']['value'] = $this->input->post('stock_unit_decimal', TRUE); + } + + if ($this->form_validation->run() == FALSE) + { + $this->messages->add(validation_errors(), 'error'); + $this->template->load('template', 'inventory/stockunit/edit', $data); + return; + } + else + { + $data_id = $id; + $data_stock_unit_symbol = $this->input->post('stock_unit_symbol', TRUE); + $data_stock_unit_name = $this->input->post('stock_unit_name', TRUE); + $data_stock_unit_decimal = $this->input->post('stock_unit_decimal', TRUE); + + $this->db->trans_start(); + $update_data = array( + 'symbol' => $data_stock_unit_symbol, + 'name' => $data_stock_unit_name, + 'decimal_places' => $data_stock_unit_decimal, + ); + if ( ! $this->db->where('id', $data_id)->update('stock_units', $update_data)) + { + $this->db->trans_rollback(); + $this->messages->add('Error updating Stock Unit - ' . $data_stock_unit_name . '.', 'error'); + $this->logger->write_message("error", "Error updating Stock Unit named " . $data_stock_unit_name . " [id:" . $data_id . "]"); + $this->template->load('template', 'inventory/stockunit/edit', $data); + return; + } else { + $this->db->trans_complete(); + $this->messages->add('Updated Stock Unit - ' . $data_stock_unit_name . '.', 'success'); + $this->logger->write_message("success", "Udpated Stock Unit named " . $data_stock_unit_name . " [id:" . $data_id . "]"); + redirect('inventory/account'); + return; + } + } + return; + } + + function delete($id) + { + /* Check access */ + if ( ! check_access('delete stock unit')) + { + $this->messages->add('Permission denied.', 'error'); + redirect('inventory/account'); + return; + } + + /* Check for account lock */ + if ($this->config->item('account_locked') == 1) + { + $this->messages->add('Account is locked.', 'error'); + redirect('inventory/account'); + return; + } + + /* Checking for valid data */ + $id = $this->input->xss_clean($id); + $id = (int)$id; + if ($id < 1) { + $this->messages->add('Invalid Stock Unit.', 'error'); + redirect('inventory/account'); + return; + } + + /* Get the stock unit details */ + $this->db->from('stock_units')->where('id', $id); + $stock_unit_q = $this->db->get(); + if ($stock_unit_q->num_rows() < 1) + { + $this->messages->add('Invalid Stock Unit.', 'error'); + redirect('inventory/account'); + return; + } else { + $stock_unit_data = $stock_unit_q->row(); + } + + /* Deleting group */ + $this->db->trans_start(); + if ( ! $this->db->delete('stock_units', array('id' => $id))) + { + $this->db->trans_rollback(); + $this->messages->add('Error deleting Stock Unit - ' . $stock_unit_data->name . '.', 'error'); + $this->logger->write_message("error", "Error deleting Stock Unit named " . $stock_unit_data->name . " [id:" . $id . "]"); + redirect('inventory/account'); + return; + } else { + $this->db->trans_complete(); + $this->messages->add('Deleted Stock Unit - ' . $stock_unit_data->name . '.', 'success'); + $this->logger->write_message("success", "Deleted Stock Unit named " . $stock_unit_data->name . " [id:" . $id . "]"); + redirect('inventory/account'); + return; + } + return; + } +} + +/* End of file stockunit.php */ +/* Location: ./system/application/controllers/inventory/stockunit.php */ diff --git a/system/application/controllers/inventory/welcome.php b/system/application/controllers/inventory/welcome.php new file mode 100644 index 0000000..3a2513b --- /dev/null +++ b/system/application/controllers/inventory/welcome.php @@ -0,0 +1,18 @@ +<?php + +class Welcome extends Controller { + + function Welcome() + { + parent::Controller(); + return; + } + + function index() + { + redirect('inventory/account'); + } +} + +/* End of file welcome.php */ +/* Location: ./system/application/controllers/inventory/welcome.php */ diff --git a/system/application/helpers/access_helper.php b/system/application/helpers/access_helper.php index 09ba678..86c939d 100644 --- a/system/application/helpers/access_helper.php +++ b/system/application/helpers/access_helper.php @@ -19,6 +19,9 @@ * 'create group' * 'edit group' * 'delete group' + * 'create stock unit' + * 'edit stock unit' + * 'delete stock unit' * 'create tag' * 'edit tag' * 'delete tag' @@ -51,6 +54,9 @@ if ( ! function_exists('check_access')) 'create group', 'edit group', 'delete group', + 'create stock unit', + 'edit stock unit', + 'delete stock unit', 'create tag', 'edit tag', 'delete tag', @@ -75,6 +81,9 @@ if ( ! function_exists('check_access')) 'create group', 'edit group', 'delete group', + 'create stock unit', + 'edit stock unit', + 'delete stock unit', 'create tag', 'edit tag', 'delete tag', diff --git a/system/application/views/inventory/account/index.php b/system/application/views/inventory/account/index.php new file mode 100644 index 0000000..107a44c --- /dev/null +++ b/system/application/views/inventory/account/index.php @@ -0,0 +1,26 @@ +<?php + echo "<table>"; + echo "<tr valign=\"top\">"; + echo "<td>"; + echo "<table border=0 cellpadding=5 class=\"simple-table account-table\">"; + echo "<thead><tr><th>Account Name</th><th>Type</th><th>O/P Balance</th><th>C/L Balance</th><th></th></tr></thead>"; + echo "</table>"; + echo "</td>"; + echo "</tr>"; + echo "</table>"; + + echo "<table border=0 cellpadding=5 class=\"simple-table float-right\">"; + echo "<thead><tr><th>Stock Unit</th><th>Symbol</th><th></th></tr></thead>"; + foreach ($stock_units->result() as $row) + { + echo "<tr>"; + echo "<td>" . $row->name . "</td>"; + echo "<td>" . $row->symbol . "</td>"; + echo "<td>" . anchor('inventory/stockunit/edit/' . $row->id , "Edit", array('title' => 'Edit Stock Unit', 'class' => 'red-link')); + echo " "; + echo anchor('inventory/stockunit/delete/' . $row->id , img(array('src' => asset_url() . "images/icons/delete.png", 'border' => '0', 'alt' => 'Delete Stock Unit', 'class' => "confirmClick", 'title' => "Delete Stock Unit")), array('title' => 'Delete Stock Unit')) . "</td>"; + echo "</tr>"; + + } + echo "</table>"; + diff --git a/system/application/views/inventory/stockunit/add.php b/system/application/views/inventory/stockunit/add.php new file mode 100644 index 0000000..4ecd28c --- /dev/null +++ b/system/application/views/inventory/stockunit/add.php @@ -0,0 +1,31 @@ +<?php + echo form_open('inventory/stockunit/add'); + + echo "<p>"; + echo form_label('Stock unit symbol', 'stock_unit_symbol'); + echo "<br />"; + echo form_input($stock_unit_symbol); + echo "</p>"; + + echo "<p>"; + echo form_label('Stock unit name', 'stock_unit_name'); + echo "<br />"; + echo form_input($stock_unit_name); + echo "</p>"; + + echo "<p class=\"affects-gross\">"; + echo "<span id=\"tooltip-target-1\">"; + echo form_label('Decimal Places', 'stock_unit_decimal'); + echo "<br />"; + echo form_input($stock_unit_decimal); + echo "</span>"; + echo "<span id=\"tooltip-content-1\">Maximum number of decimal places supported is 4.</span>"; + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Create'); + echo " "; + echo anchor('inventory/account', 'Back', 'Back to Inventory'); + echo "</p>"; + + echo form_close(); diff --git a/system/application/views/inventory/stockunit/edit.php b/system/application/views/inventory/stockunit/edit.php new file mode 100644 index 0000000..12930e5 --- /dev/null +++ b/system/application/views/inventory/stockunit/edit.php @@ -0,0 +1,31 @@ +<?php + echo form_open('inventory/stockunit/edit/' . $stock_unit_id); + + echo "<p>"; + echo form_label('Stock unit symbol', 'stock_unit_symbol'); + echo "<br />"; + echo form_input($stock_unit_symbol); + echo "</p>"; + + echo "<p>"; + echo form_label('Stock unit name', 'stock_unit_name'); + echo "<br />"; + echo form_input($stock_unit_name); + echo "</p>"; + + echo "<p class=\"affects-gross\">"; + echo "<span id=\"tooltip-target-1\">"; + echo form_label('Decimal Places', 'stock_unit_decimal'); + echo "<br />"; + echo form_input($stock_unit_decimal); + echo "</span>"; + echo "<span id=\"tooltip-content-1\">Maximum number of decimal places supported is 4.</span>"; + echo "</p>"; + + echo "<p>"; + echo form_submit('submit', 'Udpate'); + echo " "; + echo anchor('inventory/account', 'Back', 'Back to Inventory'); + echo "</p>"; + + echo form_close(); diff --git a/system/application/views/template.php b/system/application/views/template.php index cc7e883..adba3cb 100644 --- a/system/application/views/template.php +++ b/system/application/views/template.php @@ -113,6 +113,9 @@ $(document).ready(function() { <?php echo anchor('account', 'Accounts', array('title' => 'Chart of accounts')); ?> </li> <li> + <?php echo anchor('inventory', 'Inventory', array('title' => 'Inventory')); ?> + </li> + <li> <?php /* Showing Voucher Type sub-menu */ $voucher_type_all = $this->config->item('account_voucher_types');
webzash-developers@lists.fedorahosted.org