const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const ObjectId = Schema.Types.ObjectId;
/********** Define Schema ***********/
let OrderSchema = new Schema({
shortid : String,
//ID cơ hội để tham chiếu
opportunity : ObjectId,
//Thông tin người bán hàng
assignee : ObjectId, //Người được phân công,
assignee_name : String, //Tên người được phân công -> Fixed
assignee_group : String, //Nhóm được phân công -> Fixed
// Thông tin khách hàng
customer_name : String,
customer_phone : String,
customer_address : String,
customer_bill_address : String,
customer_birthday : String,
customer_identity_number : String, //CMT(căn cước)
customer_identity_date : String, //Ngày cấp
customer_identity_city : String, //Nơi cấp
//Thông tin cơ hội
source : String, // -> Fixed
status : {type : String, default : "processing"}, // processing | finished | canceled | returned
price : Number, // Giá bán
wanted_number : String, // Số điện thoại khách hàng muốn mua
delivery_type : Number, // Loại giao sim
delivery_type_name: String, // Tên loại giao sim
//Comment chính
comment : [{
system : {type : Boolean, default : false}, //Comment của hệ thống hay không?
user : ObjectId,
username : String,
message : String,
created_at : {default : new Date, type: Date}
}],
//Đính kèm
files : [{
link : String,
thumb : String,
created_at : {default : new Date, type: Date}
}],
/* Thông tin của các bộ phận liên quan */
//Processor
sim_process_status : String,
//COD
cod_info : {
status : {type : String, default : "none"}, // none | processing | finished
region : String, // hn or hcm
name : String,
phone : String,
address : String,
code : String
},
//Cashier
cashier_info : {
revenue : Number,
must_pay : { // Cần trả
agency_id : String,
value : Number
},
must_rev : { // Cần thu
agency_id : String,
value : Number
},
sell_price : Number, // Giá bán
original_price : Number, // Giá gốc
agency_delivery_fee : Number, // Phí giao hộ
cod_fee : Number, // Chí phí vận chuyển
sim_price : Number, // Chi phí sim trắng
customer_deposit : Number, // Khách đặt cọc
agency_deposit : Number, // Đặt cọc thợ
other_fee : Number // Chi phí phát sinh khác
},
is_deleted : {default : false, type: Boolean},
created_at : {default : new Date, type: Date},
updated_at : {default : new Date, type: Date}
});
/********** Methods ***********/
/********** Static functions ***********/
/********** Export Schema ***********/
module.exports = mongoose.model('Order', OrderSchema);
//Lấy các bản ghi công nợ nhóm theo id của thợ và loại công nơ
db.getCollection("cashio").aggregate([{
$group: {
_id: {agency : "$agency_id", type : "$type"},
"records": {
$push: "$$ROOT"
},
}
}])
<div class="page-title fixed">
<div class="row">
<div class="title">
<h4 class="col s6">Tạo đơn hàng mới từ cơ hội</h4>
</div>
</div>
</div> <!-- End tille -->
<div class="mt-50">
<div class="row">
<div class="col s7">
<div class="card">
<div class="content p-25">
<form (ngSubmit)="onCreateOrder()" #f="ngForm">
<div class="row">
<div class="col s6">
<strong>Thông tin sim</strong>
<hr>
<div class="input-field" *ngIf="orderConfig">
<label class="active">Hình thức giao sim</label>
<select name="delivery_type" ngModel (click)="onShipTypeChange()">
<option value="" disabled selected>Lựa chọn hình thức giao sim</option>
<option *ngFor="let ship of orderConfig.ship_types" value="{{ship.id}}">{{ship.name}}</option>
</select>
<div class="error red-text delivery_type"></div>
</div>
<div class="input-field">
<label>Giá gốc</label>
<input type="text" name="original_price" ngModel/>
<div class="error red-text original_price"></div>
</div>
<br>
<strong>Thông tin thợ</strong>
<hr>
<div class="input-field">
<label>ID thợ</label>
<input type="text" name="agency_id" ngModel>
<div class="error red-text agency_id"></div>
</div>
<div class="input-field deliver_id" style="display: none">
<label>ID thợ giao hộ</label>
<input type="text" name="deliver_id" ngModel>
<div class="error red-text deliver_id"></div>
</div>
<div class="input-field delivery_fee" style="display: none">
<label>Chi phí giao hộ</label>
<input type="text" name="delivery_fee" ngModel>
<div class="error red-text delivery_fee"></div>
</div>
</div>
<div class="col s6">
<strong>Thông tin đặt cọc</strong>
<hr>
<div class="input-field">
<label>Khách đặt cọc</label>
<input type="text" name="customer_deposit" ngModel>
<div class="error red-text customer_deposit"></div>
</div>
<div class="input-field">
<label>Đặt cọc thợ</label>
<input type="text" name="agency_deposit" ngModel>
<div class="error red-text agency_deposit"></div>
</div>
<br>
<strong>Thông tin khác</strong>
<hr>
<div class="input-field cod_type" *ngIf="orderConfig" style="display: none;">
<label class="active">Loại COD</label>
<select name="cod_type" id="">
<option value="" disabled selected>Lựa chọn loại COD</option>
<option *ngFor="let cod of orderConfig.cod_types" value="{{cod.id}}">{{cod.name}}</option>
</select>
<div class="error red-text delivery_type"></div>
</div>
<div class="input-field">
<input type="checkbox" id="sim_process" name="sim_process" ngModel>
<label for="sim_process">Giao dịch này có yêu cầu đấu nối</label>
<div class="error red-text sim_process pt-15"></div>
</div>
</div>
</div>
<div class="h-100"></div>
<div class="col s12">
<input type="submit" value="Tạo đơn hàng" class="btn btn-small green">
<a routerLink="/co-hoi" class="btn btn-small red">Quay lại</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="page-title">
<div class="row">
<div class="title">
<h4 class="col s6">Danh sách cơ hội</h4>
<div class="btn-group right pr-26 pt-5">
<button
class="btn btn-small gray lighten-1 z-depth-0"
title="Cơ hội mới"
[ngClass]="filterStatus == 'new' ? 'orange' : 'gray'"
(click)="onFilter('new')"
>
<i class="wi wi-stars"></i>
</button>
<button class="btn btn-small lighten-1 z-depth-0" title="Cơ hội đã kiếm tra"
[ngClass]="filterStatus == 'checked' ? 'orange' : 'gray'"
(click)="onFilter('checked')"
>
<i class="mdi mdi-navigation-check"></i>
</button>
<button class="btn btn-small lighten-1 z-depth-0" title="Cơ hội đã liên hệ"
[ngClass]="filterStatus == 'contacted' ? 'orange' : 'gray'"
(click)="onFilter('contacted')"
>
<i class="mdi mdi-communication-phone"></i>
</button>
<button class="btn btn-small lighten-1 z-depth-0" title="Cơ hội đã hủy"
[ngClass]="filterStatus == 'canceled' ? 'orange' : 'gray'"
(click)="onFilter('canceled')"
>
<i class="mdi mdi-action-delete"></i>
</button>
<button
class="btn btn-small lighten-1 z-depth-0"
title="Cơ hội được đánh dấu quan trọng"
[ngClass]="importantFilter ? 'orange' : 'gray'"
(click)="onFilter('important')"
>
<i class="mdi mdi-action-turned-in"></i>
</button>
</div>
</div>
</div>
</div> <!-- End title -->
<div class="row">
<div class="col s4">
<div class="card">
<div class="title">
<h5>Danh sách cơ hội</h5>
<div class="btn-group right">
<a routerLink="/tao-co-hoi" class="btn btn-small green lighten-1 z-depth-0" title="Tạo cơ hội mới"><i class="mdi-content-add"></i></a>
</div>
</div>
<div class="content p-8">
<table class="table table-hover opportunity-table">
<tbody>
<tr
*ngFor="let opportunity of opportunities; let i = index"
class="opportunity {{opportunity.status}}"
[ngClass]="{'active' : selectedOpportunity._id == opportunity._id}"
(click)="changeSelectedOpportunity(opportunity._id)"
>
<td>
<span class="badge" *ngIf="opportunity.important == true"><i class="mdi mdi-action-turned-in-not fs-20 red-text"></i></span>
<div *ngIf="opportunity.customer_name"><strong>Họ tên:</strong> {{opportunity.customer_name}}</div>
<div *ngIf="opportunity.customer_phone"><strong>Số điện thoại:</strong> {{opportunity.customer_phone}}</div>
<div *ngIf="opportunity.wanted_number">
<strong>Sim yêu cầu:</strong>
<a href="http://kho.topsim.vn/?s={{opportunity.wanted_number}}">{{opportunity.wanted_number}}</a>
</div>
<div><strong>Trạng thái:</strong> <span class="opportunity-status {{opportunity.status}} green-text">{{configs.statuses[opportunity.status]}}</span></div>
<div><strong>Ngày tạo:</strong> {{opportunity.created_at | date:'H:m dd/MM'}}</div>
</td>
</tr>
</tbody>
</table>
<ul class="pagination">
<li *ngIf="getPrevPage()"><a routerLink="/co-hoi" [queryParams]="{page : getPrevPage()}"><i class="mdi-navigation-chevron-left"></i></a></li>
<li
*ngFor="let page of pageRange"
[ngClass]="{active : page == currentPage}"
>
<a routerLink="/co-hoi" [queryParams]="{page : page}">{{page}}</a>
</li>
<li class="waves-effect" *ngIf="getNextPage()"><a routerLink="/co-hoi" [queryParams]="{page : getNextPage()}"><i class="mdi-navigation-chevron-right"></i></a></li>
</ul>
</div>
</div>
</div>
<div class="col s8">
<div class="card opportunity-details" *ngIf="selectedOpportunity">
<div class="title pl-16 pr-16">
<h5>Thông tin cơ hội</h5>
<div class="right">
<!-- Update status buttons -->
<button
*ngIf="selectedOpportunity.status=='new'"
class="btn btn-small waves-effect gray lighten-1 z-depth-0"
title="Đánh dấu đã kiếm tra cơ hội"
(click)="markAsChecked()"
>Đã kiểm tra</button>
<button
*ngIf="selectedOpportunity.status=='checked'"
class="btn btn-small waves-effect gray lighten-1 z-depth-0"
title="Đánh dấu đã liên hệ với khách hàng"
(click)="markAsContacted()"
>Đã liên hệ</button>
<button
*ngIf="selectedOpportunity.status=='contacted'"
class="btn btn-small waves-effect green lighten-1 z-depth-0"
title="Chuyển cơ hội thành đơn hàng"
(click)="checkOpportunity()"
>Tạo đơn hàng</button>
<!-- Cancel & Restore selectedOpportunity -->
<button
class="btn btn-small waves-effect red lighten-1 z-depth-0"
title="Hủy cơ hội" *ngIf="selectedOpportunity.status!='canceled'"
(click)="markAsCanceled()"
>Hủy cơ hội</button>
<button class="btn btn-small waves-effect orange lighten-1 z-depth-0" title="Hủy cơ hội" *ngIf="selectedOpportunity.status=='canceled'" (click)="restoreOpportunity()">Phục hồi</button>
</div>
</div>
<div class="content p-16">
<span class="badge" *ngIf="selectedOpportunity.important == true"><i class="mdi mdi-action-turned-in-not fs-20 red-text"></i></span>
<div class="col s12 pb-0"><strong>ID:</strong> {{selectedOpportunity._id}}</div>
<div class="col s12 pb-0"><strong>Nhóm bán hàng:</strong> {{selectedOpportunity.assignee_group_name}}</div>
<div class="col s12 pb-0"><strong>Nguồn tạo cơ hội:</strong> {{configs.sources[selectedOpportunity.source]}}</div>
<div class="col s12 pb-0"><strong>Trạng thái:</strong> <span class="opportunity-status {{selectedOpportunity.status}} green-text">{{configs.statuses[selectedOpportunity.status]}}</span></div>
<div class="col s12 pb-0"><strong>Ngày tạo:</strong> {{selectedOpportunity.created_at | date:'H:m dd/MM'}}</div>
<div class="col s12 pb-0"><strong>Website:</strong> simthanglong.vn</div>
<hr>
<div class="row" *ngIf="!editMode">
<div class="col s12">
<div *ngIf="selectedOpportunity.customer_name"><strong>Họ tên:</strong> {{selectedOpportunity.customer_name}}</div>
<div *ngIf="selectedOpportunity.customer_phone"><strong>Số điện thoại:</strong> {{selectedOpportunity.customer_phone}}</div>
<div *ngIf="selectedOpportunity.customer_address"><strong>Địa chỉ:</strong> {{selectedOpportunity.customer_address}}</div>
<hr>
<div *ngIf="selectedOpportunity.wanted_number">
<strong>Sim yêu cầu:</strong>
<a href="http://kho.topsim.vn/?s={{selectedOpportunity.wanted_number}}">{{selectedOpportunity.wanted_number}}</a>
</div>
<div><strong>Giá dự kiến:</strong> <span class="price">{{selectedOpportunity.price | number:'4.0'}} VND</span></div>
<br>
<button class="btn modal-trigger waves-effect btn-small gray lighten-1 z-depth-0" (click)="showEditMode()">Sửa</button>
</div>
</div>
<div class="row updateForm" *ngIf="editMode">
<div class="col s12">
<div class="col s8">
<div class="input-field">
<input type="text" class="customer_name" [value]="selectedOpportunity.customer_name || ''">
<label for="" [ngClass]="selectedOpportunity.customer_name ? 'active' : ''">Tên khách hàng</label>
<div class="error red-text customer_name customer_info"></div>
</div>
<div class="input-field">
<input type="text" class="customer_phone" [value]="selectedOpportunity.customer_phone || ''">
<label for="" [ngClass]="selectedOpportunity.customer_phone ? 'active' : ''">Số điện thoại khách hàng</label>
<div class="error red-text customer_phone"></div>
</div>
<div class="input-field">
<input type="text" class="customer_address" [value]="selectedOpportunity.customer_address || ''">
<label for="" [ngClass]="selectedOpportunity.customer_address ? 'active' : ''">Địa chỉ giao hàng</label>
<div class="error red-text customer_address"></div>
</div>
<div class="input-field">
<input type="text" class="wanted_number" [value]="selectedOpportunity.wanted_number || ''">
<label for="" class="red-text" [ngClass]="selectedOpportunity.wanted_number ? 'active' : ''">Sim yêu cầu</label>
<div class="error red-text wanted_number"></div>
</div>
<div class="input-field">
<input type="text" class="price" [value]="selectedOpportunity.price || ''">
<label for="" class="red-text" [ngClass]="selectedOpportunity.price ? 'active' : ''">Giá dự kiến</label>
<div class="error red-text price"></div>
</div>
<div class="input-field">
<input type="checkbox" id="important" class="important" [checked]="selectedOpportunity.important">
<label for="important">Đánh dấu cơ hội quan trọng</label>
</div>
</div>
<div class="col s4">
</div>
<div class="col s12">
<button class="btn modal-trigger waves-effect btn-small green lighten-1 z-depth-0" (click)="updateCommonInfor()">Lưu thông tin</button>
<button class="btn modal-trigger waves-effect btn-small red lighten-1 z-depth-0" (click)="backToViewMode()">Quay lại</button>
</div>
</div>
</div>
<div class="row" style="margin-top: 0px;">
<div class="col s12">
<hr>
<form>
<div class="form-group">
<div class="input-field">
<input type="file" id="opportunity-file" style="display: none" (change)="uploadFile()" multiple>
<label for="opportunity-file" class="btn waves-effect btn-small gray lighten-1 z-depth-0l">Đính kèm</label>
</div>
</div>
</form>
<table class="table table-hover opportunity-file" *ngIf="selectedOpportunity.files.length > 0" style="margin-top: 40px;">
<thead>
<tr>
<th>Tệp tin</th>
<th class="w-150">Hành động</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let file of selectedOpportunity.files">
<td>
<a href="{{file.link}}">
<img src="{{file.link}}" >
</a>
</td>
<td class="w-150">
<button class="btn btn-small red lighten-1 z-depth-0l" (click)="deleteFile(file._id)">Xóa</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col s12">
<hr>
<div class="opportunity-comments p-8">
<ul>
<li *ngFor="let comment of selectedOpportunity.comment">
<span class="time">{{comment.created_at | date:'HH:mm dd/MM'}}</span>
<span class="red-text username" *ngIf="comment.system">hệ thống: </span>
<span class="green-text username" *ngIf="!comment.system">{{comment.username}}: </span>
<span class="message">{{comment.message}}</span>
</li>
</ul>
</div>
<div class="input-field">
<textarea class="materialize-textarea" [(ngModel)]="newComment"></textarea>
<label for="" [ngClass]="{'active' : newComment.length > 0}">Nhập nội dung</label>
</div>
<button class="btn waves-effect btn-small gray lighten-1 z-depth-0" (click)="addComment()">Thêm ghi chú</button>
</div>
</div>
</div>
</div>
</div>
</div>