From c4f23dc3f1056391a69601a7b889812dc9b031bd Mon Sep 17 00:00:00 2001
From: Wiwit Rifa'i <wiwitrifai@gmail.com>
Date: Sun, 15 May 2016 15:23:20 +0700
Subject: [PATCH] add unit to objectsell

---
 .../app/Http/Controllers/ObjectSellController.php     |  8 ++++++++
 .../migrations/2016_04_04_022615_object_sell.php      |  1 +
 .../migrations/2016_04_05_150010_object_sell_log.php  |  2 ++
 ...016_04_06_054018_user_log_after_update_trigger.php |  2 +-
 ...06_062533_object_sell_log_after_insert_trigger.php |  2 ++
 ...06_063143_object_sell_log_after_update_trigger.php |  2 ++
 IES-Bandung/public/js/simple.js                       |  2 +-
 IES-Bandung/resources/views/vendorUser.blade.php      | 11 ++++++++++-
 8 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/IES-Bandung/app/Http/Controllers/ObjectSellController.php b/IES-Bandung/app/Http/Controllers/ObjectSellController.php
index 628fab6..8cef94a 100644
--- a/IES-Bandung/app/Http/Controllers/ObjectSellController.php
+++ b/IES-Bandung/app/Http/Controllers/ObjectSellController.php
@@ -33,6 +33,7 @@ class ObjectSellController extends Controller
         $item->name = $request->name;
         $item->object_type_id = $objectType->id;
         $item->price = $request->price;
+        $item->unit = $request->unit;
         $item->save();
 
         return redirect('/profile');
@@ -54,6 +55,13 @@ class ObjectSellController extends Controller
                 $item->save();
             }
         }
+        if (array_key_exists('unit', $req)) {
+            foreach ($req['unit'] as $key => $value) {
+                $item = ObjectSell::find($key);
+                $item->unit = $value;
+                $item->save();
+            }
+        }
         if (array_key_exists('type', $req)) {
             foreach ($req['type'] as $key => $value) {
                 $objectType = ObjectType::getOrCreate($value);
diff --git a/IES-Bandung/database/migrations/2016_04_04_022615_object_sell.php b/IES-Bandung/database/migrations/2016_04_04_022615_object_sell.php
index df08559..862f710 100644
--- a/IES-Bandung/database/migrations/2016_04_04_022615_object_sell.php
+++ b/IES-Bandung/database/migrations/2016_04_04_022615_object_sell.php
@@ -18,6 +18,7 @@ class ObjectSell extends Migration
             $table->string('name');
             $table->integer('object_type_id')->unsigned();
             $table->integer('price')->unsigned();
+            $table->string('unit');
             $table->string('ip_addr');
             $table->foreign('vendor_user_id')->references('id')->on('vendor_users');
             $table->foreign('object_type_id')->references('id')->on('object_types');
diff --git a/IES-Bandung/database/migrations/2016_04_05_150010_object_sell_log.php b/IES-Bandung/database/migrations/2016_04_05_150010_object_sell_log.php
index f7417f4..0845f68 100644
--- a/IES-Bandung/database/migrations/2016_04_05_150010_object_sell_log.php
+++ b/IES-Bandung/database/migrations/2016_04_05_150010_object_sell_log.php
@@ -20,6 +20,8 @@ class ObjectSellLog extends Migration
             $table->integer('object_type_id')->unsigned();
             $table->integer('old_price')->unsigned()->nullable();
             $table->integer('new_price')->unsigned()->nullable();
+            $table->string('old_unit')->nullable();
+            $table->string('new_unit')->nullable();
             $table->string('action');
             $table->string('ip_addr');
             $table->timestamps();
diff --git a/IES-Bandung/database/migrations/2016_04_06_054018_user_log_after_update_trigger.php b/IES-Bandung/database/migrations/2016_04_06_054018_user_log_after_update_trigger.php
index a85617b..1798000 100644
--- a/IES-Bandung/database/migrations/2016_04_06_054018_user_log_after_update_trigger.php
+++ b/IES-Bandung/database/migrations/2016_04_06_054018_user_log_after_update_trigger.php
@@ -18,7 +18,7 @@ class UserLogAfterUpdateTrigger extends Migration
                     AFTER UPDATE ON `users`
                     FOR EACH ROW
                     BEGIN
-                        INSERT INTO `UserLog`
+                        INSERT INTO `user_logs`
                         SET action = \'update.a\',
                             user_id = NEW.id,
                             username = NEW.username,
diff --git a/IES-Bandung/database/migrations/2016_04_06_062533_object_sell_log_after_insert_trigger.php b/IES-Bandung/database/migrations/2016_04_06_062533_object_sell_log_after_insert_trigger.php
index 2714004..d9e50d6 100644
--- a/IES-Bandung/database/migrations/2016_04_06_062533_object_sell_log_after_insert_trigger.php
+++ b/IES-Bandung/database/migrations/2016_04_06_062533_object_sell_log_after_insert_trigger.php
@@ -26,6 +26,8 @@ class ObjectSellLogAfterInsertTrigger extends Migration
                             object_type_id = NEW.object_type_id,
                             old_price = NULL,
                             new_price = NEW.price,
+                            old_unit = NULL,
+                            new_unit = NEW.unit,
                             ip_addr = NEW.ip_addr,
                             updated_at = NEW.updated_at;
                     END
diff --git a/IES-Bandung/database/migrations/2016_04_06_063143_object_sell_log_after_update_trigger.php b/IES-Bandung/database/migrations/2016_04_06_063143_object_sell_log_after_update_trigger.php
index 47d1209..f687ae3 100644
--- a/IES-Bandung/database/migrations/2016_04_06_063143_object_sell_log_after_update_trigger.php
+++ b/IES-Bandung/database/migrations/2016_04_06_063143_object_sell_log_after_update_trigger.php
@@ -26,6 +26,8 @@ class ObjectSellLogAfterUpdateTrigger extends Migration
                             object_type_id = NEW.object_type_id,
                             old_price = OLD.price,
                             new_price = NEW.price,
+                            old_unit = OLD.unit,
+                            new_unit = NEW.unit,
                             ip_addr = NEW.ip_addr,
                             updated_at = NEW.updated_at;
                     END
diff --git a/IES-Bandung/public/js/simple.js b/IES-Bandung/public/js/simple.js
index 6dc6645..5bc94cc 100644
--- a/IES-Bandung/public/js/simple.js
+++ b/IES-Bandung/public/js/simple.js
@@ -33,7 +33,7 @@ $("#editDagangBtn").on("click", function(){
 
 $(document).ready(function() {
 
-    $.getJSON("http://localhost:8888/api/object_type", function(data){
+    $.getJSON("/api/object_type", function(data){
       var availableTags = data
       $( ".suggest" ).autocomplete({
         source: availableTags
diff --git a/IES-Bandung/resources/views/vendorUser.blade.php b/IES-Bandung/resources/views/vendorUser.blade.php
index 461c3d3..30fd43d 100755
--- a/IES-Bandung/resources/views/vendorUser.blade.php
+++ b/IES-Bandung/resources/views/vendorUser.blade.php
@@ -176,6 +176,7 @@
                         <tr>
                           <th>Nama Barang</th>
                           <th>Harga</th>
+                          <th>Satuan</th>
                           <th data-breakpoints="xs sm">Jenis</th>
                           <th data-breakpoints="xs">Update</th>
                           <th>Terjual</th>
@@ -192,6 +193,10 @@
                             <input type="text" value="{{ $object->price }}" class="fedit-barang toggle-display" name="price[{{ $object->id }}]"></input>
                             <p class="tedit-barang toggle-display displayit">{{ $object->price }}</p>
                           </td>
+                          <td>
+                            <input type="text" value="{{ $object->unit }}" class="fedit-barang toggle-display" name="unit[{{ $object->id }}]"></input>
+                            <p class="tedit-barang toggle-display displayit">{{ $object->unit }}</p>
+                          </td>
                           <td>
                             <input type="text" value="{{ $object->type }}" class="suggest fedit-barang toggle-display" name="type[{{ $object->id }}]"></input>
                             <p class="tedit-barang toggle-display displayit">{{ $object->type }}</p>
@@ -232,7 +237,11 @@
                   </div>
                   <div class="form-group">
                     <label>Harga</label>
-                    <input type="text" name="price" class="form-control form-currency" placeholder="Harga Barang" required>
+                    <input type="text" name="price" class="form-control form-currency" placeholder="Harga Barang Per Satuan" required>
+                  </div>
+                  <div class="form-group">
+                    <label>Satuan</label>
+                    <input type="text" name="unit" class="form-control form-currency" placeholder="Satuan Barang" required>
                   </div>
                   <button type="submit" class="btn btn-sm btn-success">Tambahkan</button>
                   </form>
-- 
GitLab