123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- <?php
-
- namespace App\Http\Controllers\api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Api\BaseController;
-
- use Config;
- use File;
- use Carbon\Carbon;
-
- use App\Model\Staff;
- use App\Model\StaffDetail;
- use App\Model\Module\Roles;
- use App\Model\Module\Compound;
- use App\Model\Module\ConfidentialFile;
- use App\Model\Module\ItemInventory;
- use App\Model\Module\Barcode;
- use App\Model\Module\Attachment;
- use App\Model\Module\History;
- use App\Model\Module\SubHistory;
-
- use App\Jobs\GenerateBarcode;
-
- class InventoryController extends BaseController
- {
- /**
- * Create generate kpd number controller.
- *
- * @return value
- */
-
- public function iventoryList($no_siri){
-
- $nested_data = array();
- $file = ConfidentialFile::with(['ItemInventory' => function($q){
- $q->with('Attachment','Barcode')->orderBy('created_at','DESC');
- }])->where('no_siri',$no_siri)->first();
-
- $curr = Carbon::now()->getTimestamp();
- $i = 1;
- foreach($file->ItemInventory as $i)
- {
- $n1 = '';
- $reg_time = $i->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "Baru/";
- }else{
- $n1 = "";
- }
-
- $lokasi = '-';
- if($i->lokasi_gudang != '-'){
- $lokasi = $i->lokasi_gudang;
- }
- array_push($nested_data, array(
- 'tarikh' => $i->created_at->format('d/m/Y'),
- 'masa' => $i->created_at->format('h:i a'),
- 'jenis' => $i->jenis,
- 'bilangan' => $i->bilangan,
- 'harga' => $i->harga,
- 'lokasi' => $lokasi,
- 'status' => $i->status,
- 'tindakan' => $i->_id
- ));
- }
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getDetail(Request $request){
-
- $empty_attach = false; $empty_barcode = false;
- $itemI = ItemInventory::with('Attachment','Barcode')->where('_id',$request->id)->first();
- if(!empty($itemI)){
- $data = [
- '_id' => $itemI->_id,
- 'kategori' => $itemI->kategori,
- 'jenis' => $itemI->jenis,
- 'bilangan' => $itemI->bilangan,
- 'harga' => $itemI->harga,
- 'lokasi' => $itemI->lokasi_gudang,
- 'status' => $itemI->status
- ];
- return response()->json(['status' => 'true', 'desc' => $data]);
- }else{
- return response()->json(['status' => 'false', 'desc' => 'Rekod item ( '.$itemI->jenis.' ) tidak ditemui']);
- }
- }
-
- public function deleteItem(Request $request){
-
- $empty_attach = false; $empty_barcode = false;
- $itemI = ItemInventory::with('Attachment','Barcode')->where('_id',$request->id)->first();
- if(!empty($itemI)){
- $user = Staff::with('StaffDetail')->where('_id', $request->_id)->first();
- $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first();
- if(!empty($itemI->Attachment)){
- foreach($itemI->Attachment as $a){
- $a->delete();
- }
-
- $empty_attach = true;
- }else{
- $empty_attach = true;
- }
-
- if(!empty($itemI->Barcode)){
- foreach($itemI->Barcode as $b){
- $b->delete();
- }
- $empty_barcode = true;
- }else{
- $empty_barcode = true;
- }
-
- if($empty_attach == true && $empty_barcode == true){
- $itemI->delete();
-
- $now = Carbon::now();
- $gDate = $now->format('F Y');
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Pembuangan item inventori",
- 'huraian' => "Rekod Item inventori telah dibuang oleh ".$user->StaffDetail->roles_access." <a href='".url('/main/staff')."/".$user->_id."/profile'>".$user->StaffDetail->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($history);
- }
-
- return response()->json(['status' => 'true', 'desc' => 'Berjaya buang rekod item ( '.$itemI->jenis.' )']);
- }else{
- return response()->json(['status' => 'false', 'desc' => 'Tidak berjaya buang rekod item ( '.$itemI->jenis.' )']);
- }
- }else{
- return response()->json(['status' => 'false', 'desc' => 'Rekod item tidak ditemui']);
- }
- }
-
-
- /**
- * Create generate kpd number controller.
- *
- * @return value
- */
- public function iventoryListMobile(Request $request){
- $nested_data = array();
-
- $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
- if(!empty($staff)){
- $file = ConfidentialFile::with(['ItemInventory' => function($q){
- $q->with('Attachment','Barcode')->orderBy('created_at','DESC');
- }])->where('no_siri',$request->no_siri)->first();
-
- $curr = Carbon::now()->getTimestamp();
- $i = 1;
- foreach($file->ItemInventory as $i) {
- $n1 = '';
- $reg_time = $i->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "Baru/";
- }else{
- $n1 = "";
- }
-
- $lokasi = '-';
- if($i->lokasi_gudang != '-'){
- $lokasi = $i->lokasi_gudang;
- }
- array_push($nested_data, array(
- 'tarikh' => $i->created_at->format('d/m/Y'),
- 'masa' => $i->created_at->format('h:i a'),
- 'jenis' => $i->jenis,
- 'bilangan' => $i->bilangan,
- 'harga' => $i->harga,
- 'lokasi' => $lokasi,
- 'status' => $i->status,
- 'tindakan' => $i->_id
- ));
- }
- return $this->sendResponse($nested_data, 'Berjaya dapatkan senarai inventori');
- }else{
- return $this->sendError('', 'Tidak ada rekod ditemui');
- }
- }
-
- public function addItemMobile(Request $request){
-
- $data = array();
- $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
- if(!empty($staff)){
- $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first();
- if(!empty($compound)){
-
- $item = [
- 'kategori' => 'alih',
- 'jenis' => $request->get('jenis'),
- 'bilangan' => $request->get('bilangan'),
- 'harga' => $request->get('harga'),
- 'lokasi_gudang' => $request->get('lokasi'),
- 'status' => 'simpan'
- ];
-
- $itemI = ItemInventory::create($item);
- array_push($data, $itemI);
- $compound->ConfidentialFile->iteminventory()->save($itemI);
-
- if($request->has('barcode')) {
- $temp_barcode = explode(',', $request->barcode);
- foreach ($temp_barcode as $key => $b) {
- $this->dispatch(new GenerateBarcode($request->kpd, $b, $itemI));
- }
- }
-
- $now = Carbon::now();
- $gDate = $now->format('F Y');
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Ada penambahan item inventori dari penguatkuasa",
- 'huraian' => "Item inventori telah ditambah oleh ".$staff->StaffDetail->roles_access." <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($history);
- }
-
- return $this->sendResponse($data, 'Berjaya simpan item');
-
- }else{
- return $this->sendError('', 'Tiada rekod ditemui');
- }
- }
- else{
- return $this->sendError('', 'Kakitangan tidak ditemui');
- }
- }
-
- public function addItemPictureMobile(Request $request){
-
- $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
- if(!empty($staff)){
- $itemI = ItemInventory::where('_id', $request->_id)->first();
- if(!empty($itemI)){
-
- $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first();
- if(!empty($compound)){
-
- $success_upload = 0; $count_upload = 0;
- if($request->hasFile('file')) {
-
- $i = 1;
- $destinationGambarItem = 'document/'.$compound->ConfidentialFile->no_siri.'/item';
- $uploaded = public_path().'/'.$destinationGambarItem;
- if(!File::isDirectory($destinationGambarItem)){
- File::makeDirectory($destinationGambarItem, 0777, true, true);
- }
-
- $allowedfileExtension = ['jpg','jpeg'];
- $destinationPathPicture = array();
- $count_upload = count($request->file('file'));
-
- foreach($request->file('file') as $f){
- $extension = $f->getClientOriginalExtension();
- $check=in_array($extension,$allowedfileExtension);
-
- if($check) {
- $name = 'Item-'.$i++.'.'.$f->getClientOriginalExtension();
- $destinationPathPicture[] = '/'.$destinationGambarItem.'/'.$name;
- $f->move($destinationGambarItem, $name);
-
- $attach = new Attachment();
- $attach->path = '/'.$destinationGambarItem.'/'.$name;
- $itemI->attachment()->save($attach);
- $i++;
- }
- }
-
- return $this->sendResponse($destinationPathPicture, $success_upload.'/'.$count_upload.' picture compound successfully been uploaded');
-
- }else{
- return $this->sendError('', 'Tidak ada fail dimuatnaik');
- }
- }else{
- return $this->sendError('', 'Tidak ada rekod ditemui');
- }
- }else{
- return $this->sendError('', 'Tidak ada rekod ditemui');
- }
- }
- else{
- return $this->sendError('', 'Tidak ada rekod ditemui');
- }
- }
-
- public function deleteItemMobile(Request $request){
-
- $empty_attach = false; $empty_barcode = false;
- $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
- if(!empty($staff)){
- $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first();
- $itemI = ItemInventory::with('Attachment','Barcode')->where('_id',$request->id)->first();
- if(!empty($itemI)){
- if(!empty($itemI->Attachment)){
- foreach($itemI->Attachment as $a){
- $a->delete();
- }
-
- $empty_attach = true;
- }else{
- $empty_attach = true;
- }
-
- if(!empty($itemI->Barcode)){
- foreach($itemI->Barcode as $b){
- $b->delete();
- }
- $empty_barcode = true;
- }else{
- $empty_barcode = true;
- }
-
- if($empty_attach == true && $empty_barcode == true){
- $itemI->delete();
-
- $now = Carbon::now();
- $gDate = $now->format('F Y');
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Pembuangan item inventori",
- 'huraian' => "Rekod Item inventori telah dibuang oleh ".$staff->StaffDetail->roles_access." <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($history);
- }
-
- return $this->sendResponse('','Buang rekod item ( '.$itemI->jenis.' )');
- }else{
- return $this->sendError('','Buang rekod item ( '.$itemI->jenis.' )');
- }
- }else{
- return $this->sendError('','Rekod item tidak ditemui');
- }
- }
- }
-
- public function getDetailMobile(Request $request){
-
- $data = array();
- $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
- if(!empty($staff)){
- $barcode = Barcode::where('barcode_id',$request->barcode)->first();
- if(!empty($barcode)){
- $itemI = ItemInventory::with('Attachment')->where('_id',$barcode->item_inventory_id)->first();
- if(!empty($itemI)){
- array_push($data, $itemI);
- return $this->sendResponse($data, 'Rekod item ditemui');
- }else{
- return $this->sendError('','Rekod item ditemui');
- }
-
- }else{
- return $this->sendError('','Barcode tidak ditemui');
- }
- }else{
- return $this->sendError('','Kakitangan tidak ditemui');
- }
- }
- }
|