diff --git a/controllers/boxes_controller.php b/controllers/boxes_controller.php index a038bbbb..e54fd9aa 100644 --- a/controllers/boxes_controller.php +++ b/controllers/boxes_controller.php @@ -9,6 +9,12 @@ class BoxesController extends AppController { $this->set('boxes', $this->paginate()); } + + function buildForm($count = 0) { + $this->layout = 'ajax'; + $this->set('count', $count); + } + function view($id = null) { if (!$id) { $this->Session->setFlash(__('Invalid Box.', true)); diff --git a/controllers/jobs_controller.php b/controllers/jobs_controller.php index e3ccc822..b11ae466 100755 --- a/controllers/jobs_controller.php +++ b/controllers/jobs_controller.php @@ -386,110 +386,6 @@ class JobsController extends AppController { } } - - function add() { - - - - if (!empty($this->data)) { - $this->Job->create(); - - $job_offset = 6141; - - $number_of_jobs = $this->Job->findCount(); - $new_job_number = $job_offset + $number_of_jobs; - - $enquiry = $this->Job->Enquiry->findById($this->data['Job']['enquiry_id']); - - - - $monthYearShort = strtoupper(date("My")); - - $jobLetter = $enquiry['State']['enqform']; - - $this->data['Job']['title'] = $monthYearShort.$jobLetter."J".$new_job_number; - $this->data['Job']['state_id'] = $enquiry['Enquiry']['state_id']; - $this->data['Job']['customer_id'] = $enquiry['Enquiry']['customer_id']; - $this->data['Job']['contact_id'] = $enquiry['Enquiry']['contact_id']; - - - - if ($this->Job->save($this->data)) { - $jobid = $this->Job->id; - - //$this->Job->Enquiry->set('status_id', 3); //Change status to 'Job Won'; - $enquiry['Enquiry']['status_id'] = 3; - - $this->Job->Enquiry->save($enquiry); - - - $this->Session->setFlash(__('Job Saved', true)); - $this->redirect(array('action'=>'view', $jobid)); - } else { - $this->Session->setFlash(__('Please Fix the Errors Below', true)); - $enquiry = $this->Job->Enquiry->findById($this->data['Job']['enquiry_id']); - $this->set(compact('enquiry')); - } - } - else { - if(isset($this->params['named']['enquiryid'])) { - - $enquiry = $this->Job->Enquiry->findById($this->params['named']['enquiryid']); - - $this->set(compact('enquiry')); - } - else { - $this->Session->setFlash(__('Invalid Enquiry ID', true)); - $this->redirect(array('action'=>'index')); - } - } - - $freight_paid_options = array("CMC"=>"CMC", "Customer"=>"Customer"); - $this->set('freight_paid_options', $freight_paid_options); - - $sale_category_options = array("INDENT"=>"INDENT", "STOCK"=>"STOCK", "COMMISSION"=>"COMMISSION"); - $this->set('sale_category_options', $sale_category_options); - $this->set('shipment_category_options', $this->shipment_category_options()); - - } - - function edit($id = null) { - if (!$id && empty($this->data)) { - $this->flash(__('Invalid Job', true), array('action'=>'index')); - } - if (!empty($this->data)) { - $jobid = $this->data['Job']['id']; - if ($this->Job->save($this->data)) { - // $this->flash(__('The Job has been saved.', true), array('action'=>'view', $jobid)); - - $this->Session->setFlash(__('The Job has been saved', true)); - - $this->redirect(array('action' =>'view/'.$jobid), null, false); - - } else { - } - } - if (empty($this->data)) { - $job = $this->Job->read(null, $id); - $this->data = $job; - $this->set('currencies', $this->Job->Currency->find('list')); - - } - - - - - $freight_paid_options = array("CMC"=>"CMC", "Customer"=>"Customer"); - $this->set('freight_paid_options', $freight_paid_options); - - $sale_category_options = array("INDENT"=>"INDENT", "STOCK"=>"STOCK", "COMMISSION"=>"COMMISSION"); - $this->set('sale_category_options', $sale_category_options); - $this->set('shipment_category_options', $this->shipment_category_options()); - - - } - - function __isNotEmptyDate($date) { if($date == "0000-00-00") { return true; diff --git a/controllers/shipments_controller.php b/controllers/shipments_controller.php index 76604b74..ffee1135 100644 --- a/controllers/shipments_controller.php +++ b/controllers/shipments_controller.php @@ -1,8 +1,8 @@ Shipment->recursive = 0; - $this->set('shipments', $this->paginate()); + function index() { + $this->Shipment->recursive = 0; + $this->set('shipments', $this->paginate()); + } + + function view($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid Shipment.', true)); + $this->redirect(array('action'=>'index')); } + $this->set('shipment', $this->Shipment->read(null, $id)); + } - function view($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid Shipment.', true)); - $this->redirect(array('action'=>'index')); - } - $this->set('shipment', $this->Shipment->read(null, $id)); + + + + + function add($action = 'add') { + + $jobs = $this->Shipment->Job->find('list'); + $principles = $this->Shipment->Principle->find('list'); + $purchaseOrders = $this->Shipment->PurchaseOrder->find('list'); + $freightForwarders = $this->Shipment->FreightForwarder->find('list'); + $shipmentType = $this->typeOptions(); + + $this->set(compact('jobs', 'principles', 'purchaseOrders', 'freightForwarders', 'shipmentType')); + + + + } + + + function typeOptions() { + $options = array('','Import to CMC','Direct: Principle to Customer','Export','Local'); + return $options; + } + + + + function delete($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid id for Shipment', true)); + $this->redirect(array('action'=>'index')); } - - function add() { - if (!empty($this->data)) { - $this->Shipment->create(); - if ($this->Shipment->save($this->data)) { - $this->Session->setFlash(__('The Shipment has been saved', true)); - $this->redirect(array('action'=>'index')); - } else { - $this->Session->setFlash(__('The Shipment could not be saved. Please, try again.', true)); - } - } - $jobs = $this->Shipment->Job->find('list'); - $principles = $this->Shipment->Principle->find('list'); - $purchaseOrders = $this->Shipment->PurchaseOrder->find('list'); - $freightForwarders = $this->Shipment->FreightForwarder->find('list'); - $this->set(compact('jobs', 'principles', 'purchaseOrders', 'freightForwarders')); - } - - - - - function add_edit($action = 'add') { - - $principles = $this->Shipment->Principle->find('list'); - $freightForwarders = $this->Shipment->FreightForwarder->find('list'); - $this->set('principles', 'freightForwarders'); - - } - - - - - function delete($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid id for Shipment', true)); - $this->redirect(array('action'=>'index')); - } - if ($this->Shipment->del($id)) { - $this->Session->setFlash(__('Shipment deleted', true)); - $this->redirect(array('action'=>'index')); - } + if ($this->Shipment->del($id)) { + $this->Session->setFlash(__('Shipment deleted', true)); + $this->redirect(array('action'=>'index')); } + } } ?> \ No newline at end of file diff --git a/models/principle.php b/models/principle.php index a53a938d..6d940955 100755 --- a/models/principle.php +++ b/models/principle.php @@ -5,6 +5,8 @@ class Principle extends AppModel { var $recursive = 0; + var $order = 'Principle.name ASC'; + //The Associations below have been created with all possible keys, those that are not needed can be removed var $belongsTo = array( 'Country' => array('className' => 'Country', diff --git a/views/layouts/default.ctp b/views/layouts/default.ctp index 9a5608a6..50145b75 100755 --- a/views/layouts/default.ctp +++ b/views/layouts/default.ctp @@ -77,7 +77,8 @@
  • link('Shipments','/shipments/index');?>
  • diff --git a/views/shipments/add.ctp b/views/shipments/add.ctp index 591c9f53..089a17d4 100644 --- a/views/shipments/add.ctp +++ b/views/shipments/add.ctp @@ -1,35 +1,34 @@ -
    +link('shipment_add');?> + + create('Shipment');?> -
    - - input('box_count'); - echo $form->input('freight_forwarder_id'); - echo $form->input('date_arrived'); - echo $form->input('date_dispatched'); - echo $form->input('airway_bill'); - echo $form->input('comments'); - echo $form->input('Job'); - echo $form->input('Principle'); - echo $form->input('PurchaseOrder'); +
    + + + input('shipmentType', array('options'=>$shipmentType, 'id'=>'shipmentType')); + + ?> +
    + input('date_arrived_display', array('label'=>'Date Arrived', 'id'=>'date_arrived_display')); + echo $form->input('date_arrived', array('type'=>'hidden', 'id'=>'date_arrived')); ?> -
    -end('Submit');?> -
    -
    - -
    + + input('PurchaseOrder'); + echo $form->input('Job'); + echo $form->input('Principle'); + + + echo $form->input('freight_forwarder_id'); + echo $form->input('airway_bill'); + + echo $form->input('date_dispatched'); + + echo $form->input('comments'); + + ?> + +end();?> diff --git a/views/shipments/add_edit.ctp b/views/shipments/add_edit.ctp deleted file mode 100644 index c5f1111e..00000000 --- a/views/shipments/add_edit.ctp +++ /dev/null @@ -1,15 +0,0 @@ -create('Shipment');?> - - input('box_count'); - echo $form->input('freight_forwarder_id'); - echo $form->input('date_arrived'); - echo $form->input('date_dispatched'); - echo $form->input('airway_bill'); - echo $form->input('comments'); - echo $form->input('Job'); - echo $form->input('Principle'); - echo $form->input('PurchaseOrder'); - ?> -end('Submit');?> \ No newline at end of file diff --git a/views/shipments/index.ctp b/views/shipments/index.ctp index 1ca6eff7..750f1071 100644 --- a/views/shipments/index.ctp +++ b/views/shipments/index.ctp @@ -104,19 +104,7 @@
    - create('Shipment');?> - input('box_count'); - echo $form->input('freight_forwarder_id'); - echo $form->input('date_arrived'); - echo $form->input('date_dispatched'); - echo $form->input('airway_bill'); - echo $form->input('comments'); - echo $form->input('Job'); - echo $form->input('Principle'); - echo $form->input('PurchaseOrder'); - ?> - end('Submit');?> +
    \ No newline at end of file diff --git a/webroot/js/shipment_index.js b/webroot/js/shipment_index.js index 5f2b7cc4..be3b145b 100644 --- a/webroot/js/shipment_index.js +++ b/webroot/js/shipment_index.js @@ -1,82 +1,32 @@ $(function() { - - var name = $( "#name" ), - email = $( "#email" ), - password = $( "#password" ), - allFields = $( [] ).add( name ).add( email ).add( password ), - tips = $( ".validateTips" ); + + - function updateTips( t ) { - tips - .text( t ) - .addClass( "ui-state-highlight" ); - setTimeout(function() { - tips.removeClass( "ui-state-highlight", 1500 ); - }, 500 ); - } + $( "#dialog-form" ).dialog({ + autoOpen: false, + height: 600, + width: 350, + modal: true, + buttons: { + "New Shipment": function() { + + }, + Cancel: function() { + $( this ).dialog( "close" ); + } + }, + close: function() { + + } + }); - function checkLength( o, n, min, max ) { - if ( o.val().length > max || o.val().length < min ) { - o.addClass( "ui-state-error" ); - updateTips( "Length of " + n + " must be between " + - min + " and " + max + "." ); - return false; - } else { - return true; - } - } + $( "#newShipment" ).button().click(function() { - function checkRegexp( o, regexp, n ) { - if ( !( regexp.test( o.val() ) ) ) { - o.addClass( "ui-state-error" ); - updateTips( n ); - return false; - } else { - return true; - } - } + $.get('/shipments/add', function(data) { + $("#dialog-form").html(data); + $( "#dialog-form" ).dialog( "open" ); + }); - $( "#dialog-form" ).dialog({ - autoOpen: false, - height: 300, - width: 350, - modal: true, - buttons: { - "New Shipment": function() { - var bValid = true; - allFields.removeClass( "ui-state-error" ); - - bValid = bValid && checkLength( name, "username", 3, 16 ); - bValid = bValid && checkLength( email, "email", 6, 80 ); - bValid = bValid && checkLength( password, "password", 5, 16 ); - - bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." ); - // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/ - bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. ui@jquery.com" ); - bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" ); - - if ( bValid ) { - $( "#users tbody" ).append( "" + - "" + name.val() + "" + - "" + email.val() + "" + - "" + password.val() + "" + - "" ); - $( this ).dialog( "close" ); - } - }, - Cancel: function() { - $( this ).dialog( "close" ); - } - }, - close: function() { - allFields.val( "" ).removeClass( "ui-state-error" ); - } - }); - - $( "#newShipment" ) - .button() - .click(function() { - $( "#dialog-form" ).dialog( "open" ); - }); - }); \ No newline at end of file + }); +}); \ No newline at end of file