Ensure site_id is included in ORM::add(), fixed payment revendering, start product category work

This commit is contained in:
Deon George 2016-08-25 13:14:08 +10:00
parent c1cc6b6f69
commit b74fdc930f
7 changed files with 82 additions and 82 deletions

View File

@ -11,7 +11,7 @@
*/ */
class DB extends Kohana_DB { class DB extends Kohana_DB {
// Add the site_id to the delete query // Add the site_id to the delete query
public static function delete($table = NULL) final public static function delete($table = NULL)
{ {
$db = new Database_Query_Builder_Delete($table); $db = new Database_Query_Builder_Delete($table);

View File

@ -0,0 +1,23 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends Kohana's [Database_Query_Builder_Insert] to ensure that we have a site_id included in the values
*
* @package OSB
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Database_Query_Builder_Insert extends Kohana_Database_Query_Builder_Insert {
public function compile($db = NULL) {
$this->_columns = Arr::Merge($this->_columns,['site_id']);
foreach ($this->_values as $k=>$v)
$this->_values[$k] = Arr::Merge($this->_values[$k],[Site::id()]);
return parent::compile($db);
}
}
?>

View File

@ -23,19 +23,19 @@ class URL extends lnApp_URL {
foreach (array_reverse(self::$method_directory) as $k=>$v) foreach (array_reverse(self::$method_directory) as $k=>$v)
switch ($k) { switch ($k) {
case 'admin': $result[$k] = array('name'=>'Administrator','icon'=>'icon-globe'); case 'admin': $result[$k] = array('name'=>'Administrator','icon'=>'fa-globe');
break; break;
case 'affiliate': case 'affiliate':
case 'reseller': $result[$k] = array('name'=>'Reseller','icon'=>'icon-th-list'); case 'reseller': $result[$k] = array('name'=>'Reseller','icon'=>'fa-dashboard');
break; break;
case 'user': case 'user':
if (is_object(Auth::instance()->get_user())) if (is_object(Auth::instance()->get_user()))
$result[$k] = array('name'=>Auth::instance()->get_user()->name(),'icon'=>'icon-user'); $result[$k] = array('name'=>Auth::instance()->get_user()->name(),'icon'=>'fa-user');
break; break;
default: $result[$k] = array('name'=>$k,'icon'=>'icon-question-sign'); default: $result[$k] = array('name'=>$k,'icon'=>'fa-question');
} }
return $result; return $result;

View File

@ -95,7 +95,7 @@ class Controller_Admin_Payment extends Controller_Payment {
private function add_edit($id=NULL,$output='') { private function add_edit($id=NULL,$output='') {
$po = ORM::factory('Payment',$id); $po = ORM::factory('Payment',$id);
$this->meta->title = 'Payment: '.$po->refnum(TRUE); $this->meta->title = $po->loaded() ? 'Payment: '.$po->refnum(TRUE) : 'A|Payment Add';
if ($this->request->post()) { if ($this->request->post()) {
$po->values($this->request->post()); $po->values($this->request->post());
@ -113,61 +113,6 @@ class Controller_Admin_Payment extends Controller_Payment {
$this->save($po); $this->save($po);
} }
Script::factory()
->type('file')
->data('media/theme/bootstrap/js/bootstrap.datepicker.js');
Style::factory()
->type('file')
->data('media/theme/bootstrap/css/bootstrap.datepicker.css');
Script::factory()
->type('stdin')
->data('
$(document).ready(function() {
$("#date_payment_label").datepicker({
autoclose : true,
todayHighlight: true,
endDate : new Date(),
format : "dd-mm-yyyy",
todayBtn : true,
}).on("hide",function(ev) {
$("input[name=date_payment]").val(ev.date.valueOf()/1000);
});
$("input[name=account_id_label]").typeahead({
minLength: 2,
source: function (query,process) {
search("'.URL::link('admin','payment/ajaxlist').'",query,process);
},
matcher: function () { return true; },
updater: function (item) {
$("input[name=account_id]").val(users[item]);
// Send the request and update sub category dropdown
$.ajax({
type: "GET",
data: "key="+users[item],
dataType: "html",
cache: false,
url: "'.URL::link('admin','payment/ajaxitemlist',TRUE).'",
timeout: 2000,
error: function(x) {
alert("Failed to submit");
},
success: function(data) {
$("div[id=items]").empty().append(data);
}
});
return item;
},
});
});
');
if ($po->loaded()) if ($po->loaded())
Script::factory() Script::factory()
->type('stdin') ->type('stdin')

View File

@ -2,30 +2,49 @@
<fieldset> <fieldset>
<legend>Payment Details</legend> <legend>Payment Details</legend>
<label for="date_payment_label">Date Paid</label> <?php
<div class="input-group col-md-2"> echo View::factory('field/date')->set('data',['field'=>'date_payment','value'=>$o->date_payment ? $o->date_payment : time(),'text'=>'Date Charge','enddate'=>'new Date()']);
<input type="text" id="date_payment_label" value="<?php echo date('d-m-Y',$o->date_payment); ?>" class="form-control" placeholder="Date Paid"> echo View::factory('field/select')->set('data',['field'=>'checkout_id','value'=>ORM::factory('Checkout')->list_select(TRUE),'text'=>'Payment Method','default'=>$o->checkout_id,'class'=>'col-md-2']);
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-calendar"></i></span> echo View::factory('field/money')->set('data',['field'=>'total_amt','value'=>$o->total_amt,'text'=>'Total','class'=>'col-md-2']);
</div> echo View::factory('field/money')->set('data',['field'=>'fees_amt','value'=>$o->fees_amt,'text'=>'Fees','class'=>'col-md-2']);
<?php echo Form::hidden('date_payment',$o->date_payment); ?> echo View::factory('field/account')->set('data',['field'=>'account_id','value'=>$o->account_id,'text'=>'Account','name'=>$o->account_id ? sprintf('%s: %s',$o->account->refnum(),$o->account->name()) : '','ajaxurl'=>URL::link('admin','payment/ajaxlist')]);
echo View::factory('field/text')->set('data',['field'=>'notes','value'=>$o->notes,'text'=>'Notes','class'=>'col-md-5']);
<?php echo Form::select('checkout_id',ORM::factory('Checkout')->list_select(),$o->checkout_id,array('label'=>'Payment Method','required')); ?> ?>
<?php echo Form::input('total_amt',$o->total_amt,array('label'=>'Amount','placeholder'=>'Total','help-block'=>sprintf('Credits: %s, Balance: %s',$o->credit(),$o->total()))); ?>
<?php echo Form::input('fees_amt',$o->fees_amt,array('label'=>'Fees','placeholder'=>'Fees')); ?>
<?php echo Form::input('account_id_label',$o->account->name(),array('label'=>'Account','placeholder'=>'Account','data-provide'=>'typeahead')); ?>
<?php echo Form::hidden('account_id',$o->account_id); ?>
<?php echo Form::input('notes',$o->notes,array('label'=>'Notes','placeholder'=>'Any notes about this payment?')); ?>
</fieldset> </fieldset>
</div>
<fieldset class="col-md-8"> <fieldset class="col-md-8">
<legend>Invoice Details</legend> <legend>Invoice Details</legend>
<div id="items"></div> <div id="items"></div>
</fieldset> </fieldset>
<div class="row col-md-12">
<button type="submit" class="btn btn-primary">Save changes</button>
<button type="button" class="btn">Cancel</button>
</div> </div>
<div class="col-md-12">
<?php echo View::factory('field/submit'); ?>
</div>
<?php
Script::factory()
->type('stdin')
->data('
$(document).ready(function() {
$("input[name=account_id]").change(function(){
// Send the request and update sub category dropdown
$.ajax({
type: "POST",
data: "key="+$(this).val(),
dataType: "html",
cache: false,
url: "'.URL::link('admin','payment/ajaxitemlist',TRUE).'",
timeout: 2000,
error: function(x) {
alert("Failed to submit");
},
success: function(data) {
$("div[id=items]").empty().append(data);
}
});
});
});');
?>

View File

@ -14,6 +14,7 @@
*/ */
class Model_Product extends ORM { class Model_Product extends ORM {
protected $_has_many = array( protected $_has_many = array(
'product_cat'=>array('through'=>'pivot_product_cat'),
'invoice'=>array('through'=>'invoice_item'), 'invoice'=>array('through'=>'invoice_item'),
'service'=>array('far_key'=>'id'), 'service'=>array('far_key'=>'id'),
'translate'=>array('model'=>'Product_Translate','far_key'=>'id'), 'translate'=>array('model'=>'Product_Translate','far_key'=>'id'),

View File

@ -0,0 +1,12 @@
<!-- o = Array of Model_Product_Category -->
<?php echo Table::factory()
->page_items(50)
->data($o)
->columns(array(
'id'=>'ID',
'name(TRUE)'=>'Name',
))
->prepend(array(
'id'=>array('url'=>URL::link('admin','product_category/edit/')),
));
?>