> For the complete documentation index, see [llms.txt](https://kythuat.dtechvn.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kythuat.dtechvn.com/phieu-in-nhap-lieu/in-mau-dang-group.md).

# IN MẪU DẠNG GROUP

## YÊU CẦU

* Trên dữ liệu, các dòng dữ liệu thuộc 01 nhóm GroupIn
* Khi view in thì 01 nhóm GroupIn sẽ in thành 1 bộ chứng từ riêng
* Ví dụ:
  * Sổ chi tiết vật tư in liên tục: 01 vật tư khi in là 01 bộ chứng từ riêng biệt

## HƯỚNG DẪN

### Yêu cầu dữ liệu

* Có 01 cột dùng để xử lý in theo nhóm. Gọi là GroupIn
* Sắp xêp tuần tự theo GroupIn
* Trong GroupIn, sắp xếp theo 1 tiêu chí khác, để đảm bảo các lần in khác nhau đều được sắp xếp theo cùng 1 nguyên tắc

### Xử lý mẫu in

### 1. Tạo GroupHeader1 (Level0) để vẽ tiêu đề cột

* Thêm 01 groupHeader&#x20;

  <figure><img src="/files/rj419TVkduXFFWseGpbD" alt=""><figcaption><p>Tạo 01 groupHeader</p></figcaption></figure>

* Cấu hình group cho band vừa tạo&#x20;

  <figure><img src="/files/YaeozD3Uiz2Xn3Wgx3Ou" alt=""><figcaption><p>Cấu hình groupFields</p></figcaption></figure>

### 2. Tạo GroupHeader2 (Level1) để vẽ nội dung pageHeader

* Thêm 01 groupHeader&#x20;

  <figure><img src="/files/rj419TVkduXFFWseGpbD" alt=""><figcaption><p>Tạo groupHeader </p></figcaption></figure>

* Cấu hình group cho band vừa tạo&#x20;

  <figure><img src="/files/YaeozD3Uiz2Xn3Wgx3Ou" alt=""><figcaption><p>cấu hình groupFields</p></figcaption></figure>

### 3. Tạo GroupFooter để vẽ nội dung sum tổng cuối cùng của bảng

* Tạo groupFooter&#x20;

  <figure><img src="/files/7xrf6N0MhgsngEpVVqUL" alt=""><figcaption><p>Tạo 01 groupFooter - tạo nội dung sum tổng kết sau detail</p></figcaption></figure>
* Cấu hình ngắt trang giữa các group: Nếu không cấu hình thì các group sẽ in liên tục trên cùng 1 tờ giấy, mong muốn là kết thúc 1 group thì ngắt trang để in group mới&#x20;

  <figure><img src="/files/HNAWpFOpPh8fI17Xasx1" alt=""><figcaption><p>Cấu hình groupFooter - Ngắt trang</p></figcaption></figure>

### 4. Tạo detail - vẽ nộ dung lưới chi tiết

* Giữ nguyên detail&#x20;

### 5. Xử lý sum cột của detail trong mẫu in group

* Nếu không cấu hình, thì sum(cột) sẽ là sum(all dòng) của bảng dữ liệu thay vì là của các dòng trong group&#x20;

  <figure><img src="/files/wIRLcbxT0kAyLZwnqwx4" alt=""><figcaption><p>Cấu hình groupFooter - tính sum(cột) các dòng thuộc group</p></figcaption></figure>

* Xử lý đọc tiền ra chữ. Do không thể truyền thông qua biến parameter nên cần xử lý lại dataSource của phiếu in. Thêm cột docsorachu và gán nội dung vào để sử dụng trong mẫu in

```csharp
// Some code
/*
- do mẫu in theo group(kho) nên cần xử lý lại tienhang, docsorachu theo từng kho
- group kho
- sum tienhang theo kho, docsorachu theo kho
*/
if(!dt.Columns.Contains("tienhang"))
	dt.Columns.Add(new DataColumn() { ColumnName = "tienhang", DataType = typeof(int), DefaultValue = 0 });
if(!dt.Columns.Contains("docsorachu"))
	dt.Columns.Add(new DataColumn() { ColumnName = "docsorachu", DataType = typeof(string), DefaultValue = "" });
string sWhere = "";
decimal TienHang = 0, TienHangNgoaiTe = 0;
DataView dtDL = new DataView(dt);
DataTable dtKho = dtDL.ToTable(true, new string[] { "kho" });
if(_Vari.Developer || _Vari.Customer)
	{
		dtKho.TableName = "";
		_Func.ViewTable(dtKho);
	}
			
if(dtKho != null && dtKho.Rows.Count != 0)
	{
		for (int i = 0; i < dtKho.Rows.Count; i++)
			{
				swhere = "tkco like '15%' and khutrung<>3 and kho="+ dtKho.Rows[i]["kho"].ToString(); // nếu phiếu xuất thì đổi điều kiện
				//_Func.TextEditer(swhere);
				decimal.TryParse(dt.Compute("Sum(psno)", swhere).ToString(), out TienHang);
				//MessageBox.Show(TienHang.ToString());
				_Func.EditTable(dt, "tienhang", TienHang, "kho="+ dtKho.Rows[i]["kho"].ToString(), false);
				_Func.EditTable(dt, "docsorachu", formreport.BangChu(TienHang.ToString(), loaitien) , "kho="+ dtKho.Rows[i]["kho"].ToString(), false);
			}
	}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://kythuat.dtechvn.com/phieu-in-nhap-lieu/in-mau-dang-group.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
